Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

same thing db needs to be borrowed #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tutorials-book/src/ch01-06-relational-select.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @phocks, appreciate your attention to the tiny details.

The code snippet shown in the tutorial is copied from a actual Rust example. In the example the db is already a reference hence db but not &db. I want to keep it as is, adding a extra & seems trivial and Rust compiler is able to prompt user to do so.

// Relational Select
{
let la_boulangerie = bakery::ActiveModel {
name: ActiveValue::Set("La Boulangerie".to_owned()),
profit_margin: ActiveValue::Set(0.0),
..Default::default()
};
let bakery_res = Bakery::insert(la_boulangerie).exec(db).await?;
for chef_name in ["Jolie", "Charles", "Madeleine", "Frederic"] {
let chef = chef::ActiveModel {
name: ActiveValue::Set(chef_name.to_owned()),
bakery_id: ActiveValue::Set(bakery_res.last_insert_id),
..Default::default()
};
Chef::insert(chef).exec(db).await?;
}
// First find *La Boulangerie* as a Model
let la_boulangerie: bakery::Model = Bakery::find_by_id(bakery_res.last_insert_id)
.one(db)
.await?
.unwrap();
let chefs: Vec<chef::Model> = la_boulangerie.find_related(Chef).all(db).await?;
let mut chef_names: Vec<String> = chefs.into_iter().map(|b| b.name).collect();
chef_names.sort_unstable();
assert_eq!(chef_names, ["Charles", "Frederic", "Jolie", "Madeleine"]);
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ let la_boulangerie = bakery::ActiveModel {
profit_margin: ActiveValue::Set(0.0),
..Default::default()
};
let bakery_res = Bakery::insert(la_boulangerie).exec(db).await?;
let bakery_res = Bakery::insert(la_boulangerie).exec(&db).await?;

for chef_name in ["Jolie", "Charles", "Madeleine", "Frederic"] {
let chef = chef::ActiveModel {
name: ActiveValue::Set(chef_name.to_owned()),
bakery_id: ActiveValue::Set(bakery_res.last_insert_id),
..Default::default()
};
Chef::insert(chef).exec(db).await?;
Chef::insert(chef).exec(&db).await?;
}
```

Expand All @@ -31,11 +31,11 @@ There are 4 chefs working at the bakery _La Boulangerie_, and we can find them l
```rust, no_run
// First find *La Boulangerie* as a Model
let la_boulangerie: bakery::Model = Bakery::find_by_id(bakery_res.last_insert_id)
.one(db)
.one(&db)
.await?
.unwrap();

let chefs: Vec<chef::Model> = la_boulangerie.find_related(Chef).all(db).await?;
let chefs: Vec<chef::Model> = la_boulangerie.find_related(Chef).all(&db).await?;
let mut chef_names: Vec<String> = chefs.into_iter().map(|b| b.name).collect();
chef_names.sort_unstable();

Expand Down