Rename find_by to find_by_id
This commit is contained in:
parent
d8902ba979
commit
9058089dc8
@ -25,7 +25,7 @@ pub async fn insert_and_update(db: &Database) -> Result<(), ExecErr> {
|
|||||||
println!();
|
println!();
|
||||||
println!("Inserted: {:?}\n", res);
|
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)
|
.one(db)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ExecErr)?;
|
.map_err(|_| ExecErr)?;
|
||||||
|
@ -85,7 +85,7 @@ impl Cake {
|
|||||||
async fn find_one(db: &Database) -> Result<(), QueryErr> {
|
async fn find_one(db: &Database) -> Result<(), QueryErr> {
|
||||||
print!("find one by primary key: ");
|
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();
|
let cheese = cheese.unwrap();
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
@ -150,7 +150,7 @@ async fn find_many_to_many(db: &Database) -> Result<(), QueryErr> {
|
|||||||
|
|
||||||
print!("find fillings for cheese cake: ");
|
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 {
|
if let Some(cheese) = cheese {
|
||||||
let fillings: Vec<filling::Model> = cheese.find_filling().all(db).await?;
|
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: ");
|
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 {
|
if let Some(lemon) = lemon {
|
||||||
let cakes: Vec<cake::Model> = lemon.find_cake().all(db).await?;
|
let cakes: Vec<cake::Model> = lemon.find_cake().all(db).await?;
|
||||||
|
@ -262,7 +262,7 @@ where
|
|||||||
let res = exec.await?;
|
let res = exec.await?;
|
||||||
// TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value
|
// 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 {
|
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 res = find.await;
|
||||||
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
|
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
|
||||||
match model {
|
match model {
|
||||||
|
@ -61,7 +61,7 @@ pub trait EntityTrait: EntityName {
|
|||||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::PostgresQueryBuilder};
|
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::PostgresQueryBuilder};
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// cake::Entity::find_by(11)
|
/// cake::Entity::find_by_id(11)
|
||||||
/// .build(PostgresQueryBuilder)
|
/// .build(PostgresQueryBuilder)
|
||||||
/// .to_string(),
|
/// .to_string(),
|
||||||
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = 11"#
|
/// 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};
|
/// use sea_orm::{entity::*, query::*, tests_cfg::cake_filling, sea_query::PostgresQueryBuilder};
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// cake_filling::Entity::find_by((2, 3))
|
/// cake_filling::Entity::find_by_id((2, 3))
|
||||||
/// .build(PostgresQueryBuilder)
|
/// .build(PostgresQueryBuilder)
|
||||||
/// .to_string(),
|
/// .to_string(),
|
||||||
/// [
|
/// [
|
||||||
@ -81,7 +81,7 @@ pub trait EntityTrait: EntityName {
|
|||||||
/// ].join(" ")
|
/// ].join(" ")
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
fn find_by<V>(values: V) -> Select<Self>
|
fn find_by_id<V>(values: V) -> Select<Self>
|
||||||
where
|
where
|
||||||
V: IntoValueTuple,
|
V: IntoValueTuple,
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user