From 9058089dc847d021cbd74275319a9c7ab5a2785e Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Wed, 16 Jun 2021 17:39:22 +0800 Subject: [PATCH] Rename find_by to find_by_id --- examples/sqlx-mysql/src/operation.rs | 2 +- examples/sqlx-mysql/src/select.rs | 6 +++--- src/entity/active_model.rs | 2 +- src/entity/base_entity.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/sqlx-mysql/src/operation.rs b/examples/sqlx-mysql/src/operation.rs index fe21d7be..3261efe3 100644 --- a/examples/sqlx-mysql/src/operation.rs +++ b/examples/sqlx-mysql/src/operation.rs @@ -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)?; diff --git a/examples/sqlx-mysql/src/select.rs b/examples/sqlx-mysql/src/select.rs index 1945f7fd..a59b4266 100644 --- a/examples/sqlx-mysql/src/select.rs +++ b/examples/sqlx-mysql/src/select.rs @@ -85,7 +85,7 @@ impl Cake { async fn find_one(db: &Database) -> Result<(), QueryErr> { print!("find one by primary key: "); - let cheese: Option = Cake::find_by(1).one(db).await?; + let cheese: Option = 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 = 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 = lemon.find_cake().all(db).await?; diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index b70b3df8..208e0640 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -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 ::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 = res.map_err(|_| ExecErr)?; match model { diff --git a/src/entity/base_entity.rs b/src/entity/base_entity.rs index be4811b6..d28ed8e3 100644 --- a/src/entity/base_entity.rs +++ b/src/entity/base_entity.rs @@ -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(values: V) -> Select + fn find_by_id(values: V) -> Select where V: IntoValueTuple, {