mobx-rest
mobx-rest copied to clipboard
calling save on a model should add itself to its collection
Model.save
on a new model should add itself to its collection (if it has one). This was the behavior I expected, especially after playing with destroy
and how it correctly removes itself from its collection.
Simple example:
let newModel = collection.build();
await newModel.save();
collection.get(newModel.id) == newModel; // This is what is expected!
True, but we often deal with models that are either new OR existing (new/editing). It'd be nice to just call model.save()
and have it add itself to the collection, instead of needing to do:
model.isNew ? model.collection.create(model) : model.save();
This makes a lot of sense!
https://github.com/masylum/mobx-rest/pull/79
this appears to be a dupe and should be closed.