Skip to content
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

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

Closed
wuarmin opened this issue Mar 8, 2022 · 3 comments
Closed

Comments

@wuarmin
Copy link

wuarmin commented Mar 8, 2022

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"
@wuarmin
Copy link
Author

wuarmin commented Mar 8, 2022

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

@solnic
Copy link
Member

solnic commented Mar 11, 2022

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

@solnic solnic closed this as completed Mar 11, 2022
@wuarmin
Copy link
Author

wuarmin commented Mar 11, 2022

Looking forward to 6.0 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants