pub struct HasManyThrough<T>(/* private fields */);
Expand description
A “has many through” association.
Imagine you have these models:
struct User {
id: i32,
}
struct Company {
id: i32,
}
struct Employments {
id: i32,
user_id: i32,
company_id: i32,
}
For this setup we say “user has many companies through employments”. This means uses can work
at many companies and companies can have many employees, provided that we join with Employment
.
This requires that we use the JoinModel
type
on EagerLoadChildrenOfType
and is therefore a bit different from the other associations
since it involves a third type.
§Example
You can find a complete example of HasManyThrough
here.
§Attributes
Name | Description | Default | Example |
---|---|---|---|
model_field | The field on the contained type that holds the model | {name of contained type} in snakecase | model_field = company |
join_model | The model we have to join with | N/A | join_model = models::Employment |
child_primary_key_field_on_join_model | The field on the join model that holds the primary key of the child model (Company in the example above) | {name of model}_id | child_primary_key_field_on_join_model = company_identifier |
foreign_key_field | The field on the join model that holds the primary key of the parent model (User in the example above) | {name of model}_id | foreign_key_field = user_identifier |
child_primary_key_field | The field on the child model that holds its primary key | id | foreign_key_field = identifier |
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. This method will be called to filter the join models. | N/A (attribute is optional) | predicate_method = a_predicate_method |
Additionally it also supports the attributes print
, skip
, and field_arguments
. See the root model
docs for more into on those.
§Errors
try_unwrap
will never error. If the association wasn’t loaded or wasn’t found it will
return Ok(vec![])
.
Implementations§
Source§impl<T> HasManyThrough<T>
impl<T> HasManyThrough<T>
Sourcepub fn try_unwrap(&self) -> Result<&Vec<T>, Error>
pub fn try_unwrap(&self) -> Result<&Vec<T>, Error>
Borrow the loaded values. If no values have been loaded it will return an empty list. It will not return an error.
Trait Implementations§
Source§impl<T> Association<T> for HasManyThrough<T>
impl<T> Association<T> for HasManyThrough<T>
Source§fn loaded_child(&mut self, child: T)
fn loaded_child(&mut self, child: T)
Source§fn assert_loaded_otherwise_failed(&mut self)
fn assert_loaded_otherwise_failed(&mut self)
Source§impl<T: Clone> Clone for HasManyThrough<T>
impl<T: Clone> Clone for HasManyThrough<T>
Source§fn clone(&self) -> HasManyThrough<T>
fn clone(&self) -> HasManyThrough<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for HasManyThrough<T>
impl<T: Debug> Debug for HasManyThrough<T>
Source§impl<T> Default for HasManyThrough<T>
impl<T> Default for HasManyThrough<T>
Source§impl<T: Ord> Ord for HasManyThrough<T>
impl<T: Ord> Ord for HasManyThrough<T>
Source§fn cmp(&self, other: &HasManyThrough<T>) -> Ordering
fn cmp(&self, other: &HasManyThrough<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for HasManyThrough<T>
impl<T: PartialEq> PartialEq for HasManyThrough<T>
Source§impl<T: PartialOrd> PartialOrd for HasManyThrough<T>
impl<T: PartialOrd> PartialOrd for HasManyThrough<T>
impl<T: Eq> Eq for HasManyThrough<T>
impl<T> StructuralPartialEq for HasManyThrough<T>
Auto Trait Implementations§
impl<T> Freeze for HasManyThrough<T>
impl<T> RefUnwindSafe for HasManyThrough<T>where
T: RefUnwindSafe,
impl<T> Send for HasManyThrough<T>where
T: Send,
impl<T> Sync for HasManyThrough<T>where
T: Sync,
impl<T> Unpin for HasManyThrough<T>where
T: Unpin,
impl<T> UnwindSafe for HasManyThrough<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.