pub struct HasOne<T>(/* private fields */);Expand description
A non-optional “has one” association.
Imagine you have these models:
struct User {
id: i32,
country_id: i32,
}
struct Country {
id: i32,
}For this setup we say “a user has one country”. This means that User has a field named
country_id that references the id of another country.
§Example
You can find a complete example of HasOne here.
§Attributes
| Name | Description | Default | Example |
|---|---|---|---|
foreign_key_field | The name of the foreign key field | {name of field}_id | foreign_key_field = country_id |
root_model_field | The name of the field on the associated GraphQL type that holds the model | {name of field} | root_model_field = country |
graphql_field | The name of this field in your GraphQL schema | {name of field} | graphql_field = country |
child_primary_key_field | The name of the primary key field on the associated model | id | child_primary_key_field = identifier |
default | Use the default value for all unspecified attributes | N/A | default |
Additionally it also supports the attributes print, skip, and field_arguments. See the root model
docs for more into on those.
§Errors
When calling try_unwrap to get the loaded value it will return an error if the value has
not been loaded, or if the load failed.
For example if a user has a country_id of 10 but there is no Country with id 10 then
try_unwrap will return an error.
Implementations§
Trait Implementations§
Source§impl<T> Association<T> for HasOne<Box<T>>
impl<T> Association<T> for HasOne<Box<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> Association<T> for HasOne<T>
impl<T> Association<T> for HasOne<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 HasOne<T>
impl<T: Ord> Ord for HasOne<T>
Source§impl<T: PartialOrd> PartialOrd for HasOne<T>
impl<T: PartialOrd> PartialOrd for HasOne<T>
impl<T: Eq> Eq for HasOne<T>
impl<T> StructuralPartialEq for HasOne<T>
Auto Trait Implementations§
impl<T> Freeze for HasOne<T>where
T: Freeze,
impl<T> RefUnwindSafe for HasOne<T>where
T: RefUnwindSafe,
impl<T> Send for HasOne<T>where
T: Send,
impl<T> Sync for HasOne<T>where
T: Sync,
impl<T> Unpin for HasOne<T>where
T: Unpin,
impl<T> UnwindSafe for HasOne<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.