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

pushing polymorphic records to store only keeps last subtype from hasMany inverse #5055

Closed
danielspaniel opened this issue Jul 5, 2017 · 2 comments

Comments

@danielspaniel
Copy link

danielspaniel commented Jul 5, 2017

This is alittle bit hard to explain but the twiddle shows it.

If you have a model A that hasMany of a polymorphic type B
( and lets say we have subtypes B1, B2 ).

When you push polymorphic record B1 that is associated to A,
then this first record B1 is correctly added to the A's hasMany list.
If you push another B1 type record then that is added correctly.
As soon as you switch B types to, let's say B2, then B2 is added but the previous B1's are removed,
and now the hasMany will only accept B2 subtypes.

This twiddle shows the issue:

https://ember-twiddle.com/df81a058c787d97db31366f939a01591?openFiles=routes.application.js%2C

So, as long as you push the same polymorphic type, everything works fine.
If you push a different polymorphic record than the first, it clears the previous subtypes in the hasMany array and adds new one, and will now ONLY allow this new type in the array.
If you use createRecord everything works fine.

Looks like the reason createRecord works is because it takes a different path for adding it's data and relationships than push does. Push is not initializing the relationship right away ( waits for you to do a call like B1.get(A-relationship).
That means that if you say A.get(B-relationship) will always be not quite ready ( with push ). Seems like there is over optimization going on because the behaviour should be same for create or push ... I reckon.

@danielspaniel danielspaniel changed the title pushing polymorphic records to store does not add them to hasMany inverse ( as it used to ) pushing polymorphic records to store only keeps last subtype from hasMany inverse Jul 5, 2017
@BryanCrotaz
Copy link
Contributor

I think I'm seeing the same thing in #5267

@BryanCrotaz
Copy link
Contributor

Try my PR #5268 and see if it fixes the problem?

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

No branches or pull requests

2 participants