clear
clear copied to clipboard
Polymorphic Associations/Relations
Hi @anykeyh, first of all thank you for a great shard! Is there any plans to support polymorphic associations/relations similar to how it's done in Rails or Jennifer?
Hello Slava!
Currently there's no support for polymorphic association. There's only support for inherited polymorphic table.
I think this feature will be added in the next set of improvements; the next release will be focus on stability however so don't expect it before March 😄
Great news ! I follow up on this issue: In the 0.6 polymorphic association will be a reality ❤️ !!!
The only catch is it will return a "Clear::Model" at the relation, so casting / case when
must be done after reception of the payload.
Great to hear, thanks a lot!
The only catch is it will return a "Clear::Model" at the relation, so casting / case when must be done after reception of the payload.
Just wondering, what are the limitations that led to this? Seems like in Jennifer they accept a union of types for belongs_to
relation in polymorphic model, which still requires you to cast to a specific type but at least it provides some type safety here. And for has_many :polymorphic_model
they accept a concrete type, which is just awesome.
Don't to want to seem impudent, it's just I like Clear a lot and I would love to switch to it :)
I'll figure out; actually now I'm thinking to allow both: Union
type and Clear::Model
. Union type care of safety, while returning Clear::Model
allows generalization and some extensions like acts-as-taggable-on
And for has_many :polymorphic_model they accept a concrete type, which is just awesome.
I don't understand this feature, can you explain me?
actually now I'm thinking to allow both:
Union
type andClear::Model
Sounds great!
I don't understand this feature, can you explain me?
I meant you can specify something like that in Jennifer.
has_many :pictures, Picture, polymorphic: true, inverse_of: :imageable
Where Picture
has imageable_id
and imageable_type
columns.
I just thought you meant here it will return Clear::Model
as well instead of a specified class, or I'm wrong here?