My main problem with Ember Data, right now, is that when I change a relationship (hasMany or belongsTo), the parent doesn't get dirty.
I need this because:
isDirty
property to show a save/cancel buttonAlso, when I rollback the parent, only the belongsTo relationships are reverted. The hasMany models stay the same.
I've found this issue that talks about a dirtyRecordsForHasManyChange
hook, but that doesn't seem to exist in Ember Data v1 (v1.0.0-beta.3, which is what I'm using).
How can I accomplish this?
Thanks.
<br> `therefore` 512 cannot be the number of reflexive relations defined on a set A.
Polymorphism. Polymorphism is a powerful concept which allows a developer to abstract common functionality into a base class. Consider the following example: a user with multiple payment methods. They could have a linked PayPal account, and a couple credit cards on file.
In Ember Data, an Adapter determines how data is persisted to a backend data store. Things such as the backend host, URL format and headers used to talk to a REST API can all be configured in an adapter. Ember Data's default Adapter has some built-in assumptions about how a REST API should look.
One way to think about the store is as a cache of all of the records that have been loaded by your application. If a route or a controller in your app asks for a record, the store can return it immediately if it is in the cache.
For a belongsTo I added an observer.
For example in my I have Person with a belongsTo Province. On my form I have an ember select for the provinces. In the Person model I add this observer...
provinceChanged: function() {
this.send('becomeDirty');
}.observes('province')
I too am depending on isDirty for showing/hiding Save/Cancel buttons, and while that observer does a fine job at marking the record as dirty, if I hit cancel, I do the rollback, but I also need to mark the record clean. I do this in the Person controller on my cancel action.
cancel: function() {
this.get('model').rollback();
this.set('isEditing', false);
this.get('model').adapterWillCommit();
this.get('model').adapterDidCommit();
}
This all seems to be working quite well.
For hasMany on another project we used a computed property on the controller.
isThisOrChildrenDirty: function() {
return this.get('isDirty') || this.get('authors').get('isDirty');
}.property('isDirty','[email protected]')
Then instead of checking isDirty we check isThisOrChildrenDirty.
Hope that's helpful.
this.get('model').send('becomeDirty');
That should do this trick. Just send becomeDirty to the parent model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With