Trait sea_orm::entity::prelude::QueryFilter [−][src]
pub trait QueryFilter: Sized {
type QueryStatement: ConditionalStatement;
fn query(&mut self) -> &mut Self::QueryStatement;
fn filter<F>(self, filter: F) -> Self
where
F: IntoCondition,
{ ... }
fn belongs_to<M>(self, model: &M) -> Self
where
M: ModelTrait,
{ ... }
fn belongs_to_tbl_alias<M>(self, model: &M, tbl_alias: &str) -> Self
where
M: ModelTrait,
{ ... }
}
Associated Types
Required methods
fn query(&mut self) -> &mut Self::QueryStatement
Provided methods
fn filter<F>(self, filter: F) -> Self where
F: IntoCondition,
fn filter<F>(self, filter: F) -> Self where
F: IntoCondition,
Add an AND WHERE expression
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
assert_eq!(
cake::Entity::find()
.filter(cake::Column::Id.eq(4))
.filter(cake::Column::Id.eq(5))
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 AND `cake`.`id` = 5"
);
Add a condition tree.
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
assert_eq!(
cake::Entity::find()
.filter(
Condition::any()
.add(cake::Column::Id.eq(4))
.add(cake::Column::Id.eq(5))
)
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 OR `cake`.`id` = 5"
);
Add a runtime-built condition tree.
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
struct Input {
name: Option<String>,
}
let input = Input {
name: Some("cheese".to_owned()),
};
let mut conditions = Condition::all();
if let Some(name) = input.name {
conditions = conditions.add(cake::Column::Name.contains(&name));
}
assert_eq!(
cake::Entity::find()
.filter(conditions)
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
);
Add a runtime-built condition tree, functional-way.
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
struct Input {
name: Option<String>,
}
let input = Input {
name: Some("cheese".to_owned()),
};
assert_eq!(
cake::Entity::find()
.filter(
Condition::all().add_option(input.name.map(|n| cake::Column::Name.contains(&n)))
)
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
);
fn belongs_to<M>(self, model: &M) -> Self where
M: ModelTrait,
fn belongs_to<M>(self, model: &M) -> Self where
M: ModelTrait,
Apply a where condition using the model’s primary key