An issue that has come up fairly regularly for us is that structs will map to an unintended classes when using auto_struct. One such case in when an association is aliased. Something like
# we want it to map to this
class PostCategory
end
class Post < ROM::Relation[:posts]
schema do
associations do
has_one :post_category, as: :category
end
end
end
# the hacky fix
Category = PostCategory
What do you think about offering an option like: entity_implementation PostCategory? I think this would be much more predictable and won’t fail in confusing ways. Thoughts?
Sorry for the late reply, busy these last few weeks.
After thinking about this a little more, I think we definitely should add a way to ensure a proper struct/entity is generated. I see two options:
Specify the exact class that should be inherited from when building the struct class.
And/or specify the behavior the resulting struct should have by allowing modules to be included when building the class.
So something like:
class Product < ROM::Relation[:sql]
decorate(
AttachedFile[:warranty],
Reviewable,
Categorizable
)
# ...
end
This would be nice because it makes it much less tedious to setup commonly used data access methods, without having to drop into another file/etc. I often find myself hopping around to do this when all I really need is some simple behavior.
I think having the ability to do both 1 and 2 would be a huge win