Trait bound
This commit is contained in:
parent
71378350af
commit
f1165b5b8f
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ColumnTrait, ModelTrait, PrimaryKeyTrait, RelationBuilder, RelationTrait, RelationType, Select,
|
ColumnTrait, ModelTrait, PrimaryKeyTrait, RelationBuilder, RelationTrait, RelationType, Select, PrimaryKeyOfModel
|
||||||
};
|
};
|
||||||
use sea_query::{Expr, Iden, IntoIden, Value};
|
use sea_query::{Iden, IntoIden, Value};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
pub use strum::IntoEnumIterator as Iterable;
|
pub use strum::IntoEnumIterator as Iterable;
|
||||||
|
|
||||||
@ -65,12 +65,13 @@ pub trait EntityTrait: EntityName {
|
|||||||
/// ```
|
/// ```
|
||||||
fn find_by<V>(v: V) -> Select<Self>
|
fn find_by<V>(v: V) -> Select<Self>
|
||||||
where
|
where
|
||||||
V: Into<Value>,
|
V: Into<Value>, Self::PrimaryKey: PrimaryKeyOfModel<Self::Model>
|
||||||
{
|
{
|
||||||
let mut select = Self::find();
|
let mut select = Self::find();
|
||||||
if let Some(key) = Self::PrimaryKey::iter().next() {
|
if let Some(key) = Self::PrimaryKey::iter().next() {
|
||||||
// TODO: supporting composite primary key
|
// TODO: supporting composite primary key
|
||||||
select = select.filter(Expr::tbl(Self::default(), key).eq(v));
|
let col = key.into_column();
|
||||||
|
select = select.filter(col.eq(v));
|
||||||
} else {
|
} else {
|
||||||
panic!("undefined primary key");
|
panic!("undefined primary key");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user