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
When I make a hasMany relationship polymorphic, it doesn't load from the db
// some-model.js
export default Model.extend({
name: attr('string'),
myRelationshipThatIsPolymorphic: hasMany('some-other-model', {
inverse: null,
async: false, // or true, both fail
polymorphic: true
})
});
// This loads nothing, unless it is preloaded into the store
someModel.get('myRelationshipThatIsPolymorphic');
I think the problem with ember-pouch is that we now don't expect a relationship to be between multiple types. For 'normal' hasMany relationships we query all records that have a reference to its parent and filter that by type, so we don't accidentally return a record of a different type that uses the same field name. But for polymorphism we should not do this filtering, as there will be multiple model types that will have belongsTo references back to the parent. Or we should filter more broadly.
I think other database models would often use the base model and store an extra type there so you don't actually have to know all the other tables/types that should be queried to get all the items in the relationship. I guess that might be needed here too, if we don't want to change the way we query normal hasMany. But I'm not really sure if such a intermediary table would work if the base type has any attributes itself.
I've actually worked around the ember-data polymorphism by using my own intermediary type with a type attribute and a belongsTo per possible record. Might not be as clean, but it will work.
Is this still an issue? My fallback has been to manually query the child records, which is really straightforward since the id is a UUID, but then I lose automatic reloading.
When I make a hasMany relationship polymorphic, it doesn't load from the db
Also found here:
https://stackoverflow.com/questions/44187365/ember-pouch-does-not-load-hasmany-relationship-when-the-belongsto-side-is-polym
The text was updated successfully, but these errors were encountered: