Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling save on a model should add itself to its collection #51

Open
WesleyKapow opened this issue Feb 18, 2019 · 5 comments
Open

calling save on a model should add itself to its collection #51

WesleyKapow opened this issue Feb 18, 2019 · 5 comments

Comments

@WesleyKapow
Copy link

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!
@WesleyKapow WesleyKapow changed the title calling save on a resource should add itself to its collection calling save on a model should add itself to its collection Feb 18, 2019
@andresgutgon
Copy link
Collaborator

You could use collection.create

collection.create({ name: 'Jon', last_name: 'Doe' })

@WesleyKapow
Copy link
Author

WesleyKapow commented Feb 18, 2019

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();

@masylum
Copy link
Owner

masylum commented Feb 19, 2019

This makes a lot of sense!

@masylum
Copy link
Owner

masylum commented Aug 8, 2019

#79

@jeacott1
Copy link

this appears to be a dupe and should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants