rom-rb/rom

Associated entities are not mapped to their entity-classes in case of alias

wuarmin opened this issue · 3 comments

Describe the bug

I have a rom-sql project and use auto-struct with custom entity classes. That works perfectly. My repos return instances and their association-instances of my custom entity classes. However, as soon as I use the as option in an association definition, the association result is no longer mapped to the corresponding entity.

To Reproduce

module Orm
  module Relations
    class Posts < ROM::Relation[:sql]
      schema(:posts, infer: true) do
        associations do
          belongs_to :user, as: :create_user, foreign_key: :created_by
          belongs_to :user, as: :update_user, foreign_key: :updated_by
        end
      end
    end
  end
end
post = posts.combine(:create_user)
        .by_pk(1).one

expect(post).to be_a(Entities::Post) # success
expect(post.create_user).to be_a(Entities::User) # fails it is a instance of Entities::CreateUser

Expected behavior

expect(post.create_user).to be_a(Entities::User)

My environment

# ruby 2.7 Ubuntu
gem "rom", "~> 5.2"
gem "rom-sql", "~> 3.5"

That's a duplicate of #581. Sorry. But a solution would be great.

Thanks for reporting this, closing as a duplicate. It's scheduled for 6.0.

Looking forward to 6.0 👍