[][src]Struct juniper_eager_loading::HasMany

pub struct HasMany<T>(_);

A "has many" association.

Imagine you have these models:

struct User {
    id: i32,
}

struct Car {
    id: i32,
    user_id: i32,
}

For this setup we say "user has many cars" and "cars have one user". This is the inverse of a HasOne assocation because the foreign key is on Car instead of User.

This means users can own many cars, but cars can only be owned by one user.

Example

You can find a complete example of HasMany here.

Attributes

NameDescriptionDefaultExample
foreign_key_fieldThe name of the foreign key field{name of struct}_idforeign_key_field = "user_id"
foreign_key_optionalThe foreign key type is optionalNot setforeign_key_optional
root_model_fieldThe name of the field on the associated GraphQL type that holds the database modelN/A (unless using skip)root_model_field = "car"
graphql_fieldThe name of this field in your GraphQL schema{name of field}graphql_field = "country"
predicate_methodMethod used to filter child associations. This can be used if you only want to include a subset of the modelsN/A (attribute is optional)predicate_method = "a_predicate_method"

Errors

try_unwrap will never error. If the association wasn't loaded or wasn't found it will return Ok(vec![]).

Methods

impl<T> HasMany<T>[src]

pub fn try_unwrap(&self) -> Result<&Vec<T>, Error>[src]

Borrow the loaded values. If no values have been loaded it will return an empty list. It will not return an error.

Trait Implementations

impl<T> Association<T> for HasMany<T>[src]

impl<T: Clone> Clone for HasMany<T>[src]

impl<T> Default for HasMany<T>[src]

impl<T: Eq> Eq for HasMany<T>[src]

impl<T: Ord> Ord for HasMany<T>[src]

impl<T: PartialEq> PartialEq<HasMany<T>> for HasMany<T>[src]

impl<T: PartialOrd> PartialOrd<HasMany<T>> for HasMany<T>[src]

impl<T: Debug> Debug for HasMany<T>[src]

impl<T> StructuralPartialEq for HasMany<T>[src]

impl<T> StructuralEq for HasMany<T>[src]

Auto Trait Implementations

impl<T> Send for HasMany<T> where
    T: Send

impl<T> Sync for HasMany<T> where
    T: Sync

impl<T> Unpin for HasMany<T> where
    T: Unpin

impl<T> UnwindSafe for HasMany<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for HasMany<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]