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

hasMany polymorphic relationship doesn't load #220

Open
DanLeininger opened this issue Mar 11, 2018 · 2 comments
Open

hasMany polymorphic relationship doesn't load #220

DanLeininger opened this issue Mar 11, 2018 · 2 comments

Comments

@DanLeininger
Copy link

DanLeininger commented Mar 11, 2018

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');


Also found here:

https://stackoverflow.com/questions/44187365/ember-pouch-does-not-load-hasmany-relationship-when-the-belongsto-side-is-polym

@jlami
Copy link
Collaborator

jlami commented Mar 11, 2018

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.

@superlou
Copy link

superlou commented Jul 26, 2019

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.

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

3 participants