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

add upsert option to DS.create #103

Closed
kentcdodds opened this issue Jul 26, 2014 · 6 comments
Closed

add upsert option to DS.create #103

kentcdodds opened this issue Jul 26, 2014 · 6 comments
Assignees

Comments

@kentcdodds
Copy link
Contributor

My edit and create pages are the same (I think that's relatively common). In there I have this code:

var promise;
if (resource.id) {
  promise = DS.update(resourceType, resource.id, resource);
} else {
  promise = DS.create(resourceType, resource);
}
return promise;

May be cool if this was built in so I could just do:

return DS.createOrUpdate(resourceType, resource);
@jmdobry
Copy link
Member

jmdobry commented Jul 26, 2014

👍

@jmdobry jmdobry assigned jmdobry and unassigned jmdobry Jul 26, 2014
@jmdobry
Copy link
Member

jmdobry commented Jul 30, 2014

@kentcdodds How would you feel about an upsert option (default: true) added to the DS.create method. It will delegate to DS.update if attrs[definition.idAttribute] exists.

@kentcdodds
Copy link
Contributor Author

That sounds great to me...

@jmdobry jmdobry changed the title add DS.createOrUpdate add upsert option to DS.create Jul 30, 2014
@jmdobry jmdobry self-assigned this Jul 30, 2014
@kentcdodds
Copy link
Contributor Author

Looks like this is no longer the default in angular-data or js-data. Was that a conscious decision? If so, could we have an option to globally override this?

@jmdobry
Copy link
Member

jmdobry commented Dec 5, 2014

upsert defaults to true in both angular-data and js-data (but only defaults to true in js-data if it's running in the browser). Pretty much all options can be set globally, per-resource, and in the options during a method call.

@kentcdodds
Copy link
Contributor Author

I believe there's a bug with upsert, I'm preparing a PR on js-data to demostrate.

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

No branches or pull requests

2 participants