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
Difficult to implement "find or create" #1523
Comments
your last example should reduce to: findOrCreate: (type, properties)->
@store.find(type, properties.id).fail (reason)=>
if reason.status == 404
record = @store.recordForId(type, properties.id)
record.loadedData()
record.setProperties properties
record.save()
else
throw reason
|
That's so awesome :) Actually, now that I look at it having to call |
Actually, only problem there is that there's no findOrCreate: (type, properties)->
@store.find(type, properties.id).then null, (reason)=>
if reason.status == 404
record = @store.recordForId(type, properties.id)
record.loadedData()
record.setProperties(properties)
record.save()
else
throw reason |
ah good catch. |
I've made the change and added a test, but can't send the PR through GitHub until I move another fork that's already on my account. Will send it over when that's done - it's hardly a big issue :) Hey @stefanpenner, I'd really like to have a quick chat about my Ember Data pagination PR - can I get you on chat for a few minutes? Is there an IRC room we can meet in? |
channle: #ember on freenode should work. |
Okay, I'm on there as aexmachina (I think - I'm an IRC noob!) |
oops it #ember.js |
The following code is I think a reasonable way to implement a "find or create if not found" method, but it fails an assertion because "The id foo has already been used with another record of type (subclass of DS.Model)"
The workaround is as follows, but I think that calling
createRecord().save()
shouldn't result in a failed assertion.The text was updated successfully, but these errors were encountered: