we should probably get some unit tests around the following corner cases:
-
collection load's
-
a collection has been loaded and includes a particular model
-
that model is updated server-side, not on the page
-
the collection is re-loaded, and the change from the server side is applied to the local copy of the model
-
i don't know if the model triggers a change event in this case
-
pertinent code: when a query resolves and converts the plain objects into model instances
-
model creation (i.e. actually saving a new model, not just instantiating it):
-
when a model is
.save()'ed and it results in a create request, it should trigger some event on the manager, probably in theassociatemethod. let's call these events from the manager 'add' events for clarity. -
if a collection is just loading everything, i.o.w. has no query, limit, or offset, then it should probably listen for these events,
Collection#add()the new model to its set, and trigger an 'update' -
if a collection does have some sort of query, it can't be sure whether or not it should include the new model, so should it call
.refresh()? this may be too aggressive
To clarify I think what you mean by;
is
save()is called on a model that results in acreaterequest, it should trigger some event on the manager, probably in theassociatemethodThe reason being that
Manager::associateis only called in that case or duringModel::init.