rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

Table Name Issue #357

Closed richardmatthewsdev closed 7 years ago

richardmatthewsdev commented 7 years ago

Hey,

This is kind of an odd issue, but I was wanting to use ROM to read from a SilverStripe database into a rails application.

My problem is basically that SilverStripe names it's tables like Ruby names it's classes, such as 'MyTable'. So I am unable to do something like

class UserRepo < ROM::Repository[:users]
  # find all users with the given attributes
  def query(conditions)
    users.where(conditions)
  end
end

as mine would be

class UserRepo < ROM::Repository[:MyTable]
  # find all users with the given attributes
  def query(conditions)
    MyTable.where(conditions)
  end
end

Is there a way around this?

Thanks, Richard

kwando commented 7 years ago

Have you tried register relations manually?

class UsersRelation < ROM::Relation[:sql]
  register_as(:users)
  dataset(:UsersTable)
end
richardmatthewsdev commented 7 years ago

Oh na I didn't see that you could do that :). I will give that a go, thanks!

solnic commented 7 years ago

Is it still a problem?

solnic commented 7 years ago

Closing this since I'm pretty sure setting register_as solves this problem