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

Unclear error message when assigning wrong type to polymorphic relationship #4633

Closed
balinterdi opened this issue Nov 1, 2016 · 5 comments
Closed
Labels
🏷️ feat This PR introduces a new feature

Comments

@balinterdi
Copy link
Contributor

balinterdi commented Nov 1, 2016

I have the following relationships:

// app/models/business.js
import DS from 'ember-data';

const { attr, hasMany, belongsTo, Model } = DS;

export default Model.extend({
  logo:  belongsTo('image', { async: false }),
});
// app/models/image.js
import DS from 'ember-data';

const { Model, attr, belongsTo } = DS;

export default Model.extend({
  pictured:  belongsTo('pictured', { polymorphic: true })
});

When a logo.pictured relationship is set, I get the following error:

You cannot add a record of type 'business' to the 'image.pictured' relationship (only 'pictured' allowed)

I think this error might be made clearer as at the point it is thrown we know we're checking a polymorphic relationship so we might as well say:

"The business type does not implement pictured and thus cannot be assigned to the pictured relationship in image. Make it a descendant of pictured or use a mixin of the same name.

What do you think?

(Showed this to @pangratz at EmberFest a few days ago.)

@runspired
Copy link
Contributor

@balinterdi I'd be all for this :)

@pete-the-pete
Copy link
Contributor

@runspired and @balinterdi does this still need a contributor? If so, I'd like to pick it up.

@runspired
Copy link
Contributor

@pete-the-pete it does!

@balinterdi
Copy link
Contributor Author

@pete-the-pete Yes, feel free to snag it. Thank you!

@runspired
Copy link
Contributor

Resolved by #5518

@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

4 participants