pub struct HasMany<T>(/* private fields */);
Expand description
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 |
foreign_key_optional | The foreign key type is optional | Not set | foreign_key_optional |
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 |
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§
Trait Implementations§
Source§impl<T> Association<T> for HasMany<T>
impl<T> Association<T> for HasMany<T>
Source§fn loaded_child(&mut self, child: T)
fn loaded_child(&mut self, child: T)
Store the loaded child on the association.
Source§fn assert_loaded_otherwise_failed(&mut self)
fn assert_loaded_otherwise_failed(&mut self)
The association should have been loaded by now, if not store an error inside the
association (if applicable for the particular association).
Source§impl<T: Ord> Ord for HasMany<T>
impl<T: Ord> Ord for HasMany<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for HasMany<T>
impl<T: PartialOrd> PartialOrd for HasMany<T>
impl<T: Eq> Eq for HasMany<T>
impl<T> StructuralPartialEq for HasMany<T>
Auto Trait Implementations§
impl<T> Freeze for HasMany<T>
impl<T> RefUnwindSafe for HasMany<T>where
T: RefUnwindSafe,
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,
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
Mutably borrows from an owned value. Read more
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
Compare self to
key
and return true
if they are equal.