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

Combining data with sql relations #36

Open
firstsano opened this issue Dec 1, 2018 · 2 comments
Open

Combining data with sql relations #36

firstsano opened this issue Dec 1, 2018 · 2 comments

Comments

@firstsano
Copy link

Defining an associaton gives me a finalize_associations!' exception, so I guess it's not implemented. I need to combine a http relation with a sql relation. Am I not mistaking that the only option I have is to use combine_with?

@solnic
Copy link
Member

solnic commented Dec 3, 2018

Yes you could try that. We'll add support for associations eventually.

@firstsano
Copy link
Author

firstsano commented Dec 3, 2018

Thanks for response!
Okay. Now here's the tricky part. Suppose I have an http relation:

class UsersRelation < ::ROM::Relation[:http]
    gateway :my_awesome_gateway

    schema(:users) do
      attribute :id, Types::Int
      attribute :login, Types::Strict::String
      attribute :car_id, Types::Int
      primary_key :id
    end

    def by_id(id)
      with_path(id.to_s)
    end
  end

And an sql relation:

class CarsRelation < ::ROM::Relation[:sql]
  gateway :my_precious_gateway

  schema(:cars, infer: true)

  dataset do
    where(is_deleted: 0).order(:id)
  end

  def by_id(id)
    where(id: id)
  end

  def for_users(_assoc, users)
    where(id: users.map { |u| u[:car_id] })
  end
end

So when I use users.by_id(id).combine_with(cars.for_users).one it throws

ROM::MapperMisconfiguredError ([[:id], [:name], [:create_date], [:change_date], [:description]] attribute: block is required for :from with union value.):

where above-mentioned attributes are the attributes of an entity, representing a car in a database. Where should I look for the problem? I've read a lot of comments in gitter with the same problem, and I believe that the code should work.

@solnic solnic added this to the v1.0.0 milestone Apr 28, 2019
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