-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
EmberData | Polymorphic Relationship Support #793
EmberData | Polymorphic Relationship Support #793
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is headed in the right direction and mirrors what we've been discussing as the path forward for some time (simply that if the relationship definition on one model satisfies the definition on the inverse that declares itself polymorphic then that is sufficient to allow the record to satisfy the relationship). I'll leave more detailed feedback in a comment.
Some prior discussion and art:
Overall this is the direction the team has wanted to take this for sometime. I think there are a few key discussion points for us all to hash out.
// note how we explicitly declare what types can satisfy this relationship in "allowedTypes"
class Tag extends Model {
@hasMany("taggable", { inverse: "tags", polymorphic: true, allowedTypes: ["post", "comment"] }) taggables;
}
// note how we explicitly set the "base type" the relationship is satisfying here
// this side is not polymorphic as only a Tag satisfies the relationship.
class Comment extends Model {
@hasMany("tag", { inverse: "taggables", as: "taggable" }) tags;
}
|
Co-authored-by: Chris Thoburn <[email protected]>
Thank you @runspired! I've applied your feedback.
I really don't like having
Sorry, I'm not familiar with Ember Data internals, I'd assume that if class Tag extends Model {
@hasMany("taggable", { inverse: "tags", polymorphic: true }) taggables;
}
class Comment extends Model {
}
tag.taggable = comment; // => Error: Comment model doesn't have "tags"
// ======
class Tag extends Model {
@hasMany("taggable", { polymorphic: true }) taggables;
}
tag.taggable = comment; // => All good |
@yratanov I updated the RFC to fill out bits of context and design it needed as well as to update a few bits of the proposed design. To answer your above questions:
I think everyone is in agreement, but it's an alternative to consider. I've noted this in the alternatives.
This wasn't what I meant. Let's say that you have a polymorphic relationship to an abstract entity (taggable), do we require that
We need both. |
…7955) * feat: explicit relationship polymorphism * all tests passing but a few more to write * stash * cleanup tests and features * add all the tests * fix lint * fix lint
Please don't judge me, it's my first RFC :)
Some discussion here: emberjs/data#6728
rendered