-
Notifications
You must be signed in to change notification settings - Fork 33
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
Some belongs_to relationship changes not persisted #52
Comments
I'm unable to recreate this. Can you give some more context on where user, profileA, and profileB are coming from? |
Thanks for looking into it. I am running Ember rc6 and latest EPF. There is nothing unusual about the relationship setup, it is using the built-in rest adapter settings and is declared in the models as shown above. The context is not much more than is shown above, the profile ID comes from an edit user form and feeds into this logic on the controller where 'model' is the user instance: if profile_id
profile = App.Profile.find(profile_id)
@get("model").set("profile", profile)
else
@get("model").set("profile", null) This all works fine except session.flush() doesn't do anything in the case where the I've been trying to work out what is going on but the EPF internals are a bit beyond me at present. I can say for sure that in the failing case both the user and profile are marked as dirty. The session#flush method definitely has the two dirty models and the problem seems to be that the rest_adapter#flush method returns an empty array of models. This method starts off with the two dirty models fetched from the session, but somehow in the course of performing the flush they get lost. I'm not sure if this is significant but my user JSON already had an attribute called 'type', so I have changed this to 'userType' in the model and have this in my adapter: App.Adapter.map "App.User",
userType: {key: "type"} This seems to work, apart from this issue I can CRUD user models quite happily. |
I'm not positive this is the issue, but var user = this.get('model');
if (profile_id)
App.Profile.find(profile_id).then(function(profile) {
user.set('profile', profile);
});
else
user.set('profile', null);
end |
I think @jasonkriss is correct. Let us know if that works. |
I think correctly handling the promise helped a bit, the case where the user.profile starts off as null and is then assigned now works fine. I ultimately traced that to something on my side - before the profile was set to null on the user I had this code to remove the user from the profile: App.Profile.find(profile_id).get("users").removeObject(user) I didn't really need this in my code and it's a legacy of relationships not really working right in ED the last time I tried. However fair play to EPF, when I take this out it all works perfectly. I do wonder if this is highlighting a corner case bug though. The gist of what seems to be happening is that the original profile object goes into the dirty queue first, then the user. Anyway its definitely not a problem that I can see a need to hit in reality, so close this as you see fit. Thanks both for the help. |
I am going to close this issue. Let me know if this is still a problem. I think the starting point for this corner case would be a test. |
Given the following relationship:
If a user already has a profile, then this works:
However when the profile is starts off from undefined, then no PUT occurs:
Similarly changing the profile to null does not update either:
The text was updated successfully, but these errors were encountered: