[−][src]Struct juniper_eager_loading::HasMany
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
| Name | Description | Default | Example |
|---|---|---|---|
foreign_key_field | The name of the foreign key field | {name of struct}_id | foreign_key_field = "user_id" |
model | The database model type | models::{name of contained type} | model = "models::Car" |
root_model_field | The name of the field on the associated GraphQL type that holds the database model | N/A (unless using skip) | root_model_field = "car" |
graphql_field | The name of this field in your GraphQL schema | {name of field} | graphql_field = "country" |
predicate_method | Method used to filter child associations. This can be used if you only want to include a subset of the models | N/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.
pub fn loaded(&mut self, inner: T)[src]
Add the loaded value to the list.
pub fn assert_loaded_otherwise_failed(&mut self)[src]
This function doesn't do anything since the default is an empty list and there is no error state.
Trait Implementations
impl<T: PartialOrd> PartialOrd<HasMany<T>> for HasMany<T>[src]
fn partial_cmp(&self, other: &HasMany<T>) -> Option<Ordering>[src]
fn lt(&self, other: &HasMany<T>) -> bool[src]
fn le(&self, other: &HasMany<T>) -> bool[src]
fn gt(&self, other: &HasMany<T>) -> bool[src]
fn ge(&self, other: &HasMany<T>) -> bool[src]
impl<T> Default for HasMany<T>[src]
impl<T: Clone> Clone for HasMany<T>[src]
fn clone(&self) -> HasMany<T>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<T: PartialEq> PartialEq<HasMany<T>> for HasMany<T>[src]
impl<T: Eq> Eq for HasMany<T>[src]
impl<T: Ord> Ord for HasMany<T>[src]
fn cmp(&self, other: &HasMany<T>) -> Ordering[src]
fn max(self, other: Self) -> Self1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self[src]
clamp)Restrict a value to a certain interval. Read more
impl<T: Debug> Debug for HasMany<T>[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,