Recently I discovered one thing I didn’t even think about, or I believed it to work absolutely differently.
So, to explain it, given the following models:
I always believed that the collection of participants should keep the same size (zero in the above case) until I call save on the Project object. As you see the collection has been changed by 1, despite the record has not been yet save to the database; Is it a normal behaviour ?
You have added one to the collection so it appears in the collection
in memory. Note that there is no need to save the project object in
order to add to its collection as nothing in the project object
changes. It is the participant that must be saved at some point,
otherwise it will be lost.
Recently I discovered one thing I didn't even think about, or I believed it
to work absolutely differently.
So, to explain it, given the following models:
I always believed that the collection of participants should keep the same
size (zero in the above case) until I call save on the Project object. As
you see the collection has been changed by 1, despite the record has not
been yet save to the database; Is it a normal behaviour ?
You have added one to the collection so it appears in the collection
in memory. Note that there is no need to save the project object in
order to add to its collection as nothing in the project object
changes. It is the participant that must be saved at some point,
otherwise it will be lost.
Thank you, Colin, for the answer, I believed that every time you call a collection method, for example:
project.participants
a DB query will be made to get it, but it is not the case.