Trunk - Difference between Collection.add () / Collection.create ()?

I am rather confused by the differences between the two. It seems that Collection.create () ( add and sync events are triggered) can be considered as a combination of Collection.add () ( add triggered) and Model.save () ( sync triggered)?

Is this rating correct? What am I missing?

+6
source share
1 answer

It is right. This is a quick access method. Documentation Status :

create collection.create(attributes, [options])

Ease of creating a new instance of the model in the collection. It is equivalent to creating a model with an attribute hash, saving the model for the server, and adding the model to the set after successful completion.

And annotated source code :

Create a new instance of the model in this collection. Add the model to the collection immediately, if you do not wait: true is passed, in which case we wait until the server agrees.

This second description is a little more accurate, since only passing {wait:true} results in the model not being added to the collection in case of errors while saving the model.

+10
source

Source: https://habr.com/ru/post/924386/


All Articles