You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
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.
The text was updated successfully, but these errors were encountered: