AutoStruct does not respect type definitions for associations
cflipse opened this issue · 1 comments
cflipse commented
When using auto_struct and a module definition, ROM is not respecting the configured types for an association.
schema(:articles, infer: true) do
associations do
belongs_to :profiles, as: :author, foreign_key: :author_id
end
end
class Entities::Article < Entity # entity itself inherits from ROM::Struct
attribute :author, ::Entities::Profile
end
ArticleRepository.new(rom).first.author.class
# => Entities::Author ... expect an Entities::Profile
reproduction script: https://gist.github.com/cflipse/947447e4c656b35d351ffb518df38d65
Directly mapping to the class via map_to
will coerce the author field correctly.