Trait diesel::query_dsl::BelongingToDsl

source ·
pub trait BelongingToDsl<T> {
    type Output;

    // Required method
    fn belonging_to(other: T) -> Self::Output;
}
Expand description

Constructs a query that finds record(s) based on directional association with other record(s).

§Example

let sean = users.filter(name.eq("Sean")).first::<User>(connection)?;
let tess = users.filter(name.eq("Tess")).first::<User>(connection)?;

let seans_posts = Post::belonging_to(&sean)
    .select(title)
    .load::<String>(connection)?;
assert_eq!(vec!["My first post", "About Rust"], seans_posts);

// A vec or slice can be passed as well
let more_posts = Post::belonging_to(&vec![sean, tess])
    .select(title)
    .load::<String>(connection)?;
assert_eq!(vec!["My first post", "About Rust", "My first post too"], more_posts);

Required Associated Types§

source

type Output

The query returned by belonging_to

Required Methods§

source

fn belonging_to(other: T) -> Self::Output

Get the record(s) belonging to record(s) other

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, Parent, Child> BelongingToDsl<&'a [Parent]> for Child

source§

type Output = <<Child as HasTable>::Table as FilterDsl<Grouped<In<<Child as BelongsTo<Parent>>::ForeignKeyColumn, <Vec<<&'a Parent as Identifiable>::Id> as AsInExpression<<<Child as BelongsTo<Parent>>::ForeignKeyColumn as Expression>::SqlType>>::InExpression>>>>::Output

source§

impl<'a, Parent, Child> BelongingToDsl<&'a Vec<Parent>> for Child
where Child: BelongingToDsl<&'a [Parent]>,

source§

impl<'a, Parent, Child> BelongingToDsl<(&'a [Parent], &'a [Parent])> for Child

source§

type Output = <<Child as HasTable>::Table as FilterDsl<Grouped<In<<Child as BelongsTo<Parent>>::ForeignKeyColumn, <Vec<<&'a Parent as Identifiable>::Id> as AsInExpression<<<Child as BelongsTo<Parent>>::ForeignKeyColumn as Expression>::SqlType>>::InExpression>>>>::Output

source§

impl<'a, Parent, Child> BelongingToDsl<&'a Parent> for Child

source§

type Output = <<Child as HasTable>::Table as FilterDsl<Grouped<Eq<<Child as BelongsTo<Parent>>::ForeignKeyColumn, <<&'a Parent as Identifiable>::Id as AsExpression<<<Child as BelongsTo<Parent>>::ForeignKeyColumn as Expression>::SqlType>>::Expression>>>>::Output