box.Put
has been executed on the first order, the customer.Id
would be 1
because we're using pointers (Customer *Customer
field) so Put could update the variable when it has inserted the Customer. Note that this wouldn't be possible if we were using copies (Customer Customer
field) and in that case you should insert the customer manually into it's box first (or use an existing customer selected from the database).link
annotation this time because ObjectBox wouldn't know how to store a slice of structs by itself anyway so it assumes it must be a many-to-may relation. They're stored when you put the source entity and loaded when you read it from the database, unless you specify a lazy
annotation in which case, they're loaded manually, using Box::GetRelated()
.student.Teachers
slice to reflect the new state (i.e. remove element, add elements, etc) and box.Put(student)
. Note that if you want to change actual teacher data (e.g. change teachers name), you need to update the teacher entity itself, not just change it in one of the student.Teachers slice.Student
object, the Teachers
field would be nil
and you can work with the student as you wish, changing it and saving and the list of assigned teachers wouldn't change as long as the Teachers
field stays nil
. If it wasn't nil
, but a slice of Teachers instead, ObjectBox would recognize this as an update of the field and replace the relational links.Teachers
, we need to first load them. ObjectBox has generated a helper method just for thatTeachers
, we can either overwrite the slice with completely new data (new slice), or if we want to keep the original data and update it, e.g. change a few items, we need to load them first the same way as when reading (above).