Closed mptre closed 12 years ago
Please let me know if I can supply you with any more info or examples.
What's happening is that the persisted model is Application
, and it has children which are Post
instances. When one of the Post
instances changes it does not cause the Application
model to persist itself.
Once we support inverse associations (see #8), we might be able to make this work more magically, by checking whether the association is serialized or not.
Until then, you're going to have to manually persist the application model after you change the post attribute. You can do this by calling my_application.save()
. You should also be able to add this to your model layer, so you don't have to explicitly do it in the controller.
Thanks for the info. Is the change
event triggered recursively on the models? Can I simply bind to the change
event on the Application model and then call the save
method?
Application.bind('change', function () {
this.save();
});
No, you can't. That's the whole problem. If it were called "recursively" you wouldn't have to do anything.
Ah sorry, I'm the one being a bit slow here. Found a solution that works by now.
var application = Application.find(1);
var Post = Serenade.Model.extend('post', function () {
this.bind('change', function () {
application.save();
});
});
Yes that should do it! Ideally we'll be able to infer this automatically in the future.
This bug first occurred with v0.1.1. Unfortunately it seems to back with v0.2.1. In order to reproduce this bug follow the instructions below:
read
attribute haven't been properly stored.