Rename find_by to find_by_id

This commit is contained in:
Chris Tsang 2021-06-16 17:39:22 +08:00
parent d8902ba979
commit 9058089dc8
4 changed files with 8 additions and 8 deletions

View File

@ -25,7 +25,7 @@ pub async fn insert_and_update(db: &Database) -> Result<(), ExecErr> {
println!();
println!("Inserted: {:?}\n", res);
let pear = Fruit::find_by(res.last_insert_id)
let pear = Fruit::find_by_id(res.last_insert_id)
.one(db)
.await
.map_err(|_| ExecErr)?;

View File

@ -85,7 +85,7 @@ impl Cake {
async fn find_one(db: &Database) -> Result<(), QueryErr> {
print!("find one by primary key: ");
let cheese: Option<cake::Model> = Cake::find_by(1).one(db).await?;
let cheese: Option<cake::Model> = Cake::find_by_id(1).one(db).await?;
let cheese = cheese.unwrap();
println!();
@ -150,7 +150,7 @@ async fn find_many_to_many(db: &Database) -> Result<(), QueryErr> {
print!("find fillings for cheese cake: ");
let cheese = Cake::find_by(1).one(db).await?;
let cheese = Cake::find_by_id(1).one(db).await?;
if let Some(cheese) = cheese {
let fillings: Vec<filling::Model> = cheese.find_filling().all(db).await?;
@ -163,7 +163,7 @@ async fn find_many_to_many(db: &Database) -> Result<(), QueryErr> {
print!("find cakes for lemon: ");
let lemon = Filling::find_by(2).one(db).await?;
let lemon = Filling::find_by_id(2).one(db).await?;
if let Some(lemon) = lemon {
let cakes: Vec<cake::Model> = lemon.find_cake().all(db).await?;

View File

@ -262,7 +262,7 @@ where
let res = exec.await?;
// TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value
if <E::PrimaryKey as PrimaryKeyTrait>::auto_increment() && res.last_insert_id != 0 {
let find = E::find_by(res.last_insert_id).one(db);
let find = E::find_by_id(res.last_insert_id).one(db);
let res = find.await;
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
match model {

View File

@ -61,7 +61,7 @@ pub trait EntityTrait: EntityName {
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::PostgresQueryBuilder};
///
/// assert_eq!(
/// cake::Entity::find_by(11)
/// cake::Entity::find_by_id(11)
/// .build(PostgresQueryBuilder)
/// .to_string(),
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = 11"#
@ -72,7 +72,7 @@ pub trait EntityTrait: EntityName {
/// use sea_orm::{entity::*, query::*, tests_cfg::cake_filling, sea_query::PostgresQueryBuilder};
///
/// assert_eq!(
/// cake_filling::Entity::find_by((2, 3))
/// cake_filling::Entity::find_by_id((2, 3))
/// .build(PostgresQueryBuilder)
/// .to_string(),
/// [
@ -81,7 +81,7 @@ pub trait EntityTrait: EntityName {
/// ].join(" ")
/// );
/// ```
fn find_by<V>(values: V) -> Select<Self>
fn find_by_id<V>(values: V) -> Select<Self>
where
V: IntoValueTuple,
{