Struct butane_core::many::Many
source · pub struct Many<T>where
T: DataObject,{ /* private fields */ }
Expand description
Used to implement a many-to-many relationship between models.
Creates a new table with columns “owner” and “has” If type T has a many-to-many relationship with U, owner type is T::PKType, has is U::PKType. Table name is T_foo_Many where foo is the name of the Many field
Implementations§
source§impl<T> Many<T>where
T: DataObject,
impl<T> Many<T>where T: DataObject,
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new Many. init
must be called before it can be
loaded or saved (or those methods will return
Error::NotInitialized
). init
will automatically be called
when a DataObject
with a Many
field is loaded or saved.
sourcepub fn ensure_init(
&mut self,
item_table: &'static str,
owner: SqlVal,
owner_type: SqlType
)
pub fn ensure_init( &mut self, item_table: &'static str, owner: SqlVal, owner_type: SqlType )
Used by macro-generated code. You do not need to call this directly.
sourcepub fn add(&mut self, new_val: &T) -> Result<()>
pub fn add(&mut self, new_val: &T) -> Result<()>
Adds a value. Returns Err(ValueNotSaved) if the provided value uses automatic primary keys and appears to have an uninitialized one.
sourcepub fn get(&self) -> Result<impl Iterator<Item = &T>>
pub fn get(&self) -> Result<impl Iterator<Item = &T>>
Returns a reference to the value. It must have already been loaded. If not, returns Error::ValueNotLoaded
sourcepub fn save(&mut self, conn: &impl ConnectionMethods) -> Result<()>
pub fn save(&mut self, conn: &impl ConnectionMethods) -> Result<()>
Used by macro-generated code. You do not need to call this directly.
sourcepub fn load(
&self,
conn: &impl ConnectionMethods
) -> Result<impl Iterator<Item = &T>>
pub fn load( &self, conn: &impl ConnectionMethods ) -> Result<impl Iterator<Item = &T>>
Loads the values referred to by this foreign key from the database if necessary and returns a reference to them.