0

How I can get the same result using ActiveRecord?

SELECT categories.* FROM categories
INNER JOIN levels ON levels.id = categories.level_id where levels.description <= "Medium"
Marcelo De Polli
  • 28,123
  • 4
  • 37
  • 47
user588324
  • 310
  • 1
  • 6
  • 19

1 Answers1

1

It's hard to be precise without more details, but it should be something like that:

Category.joins(:level).where('levels.description <= "Medium"')

I think this should also do the trick:

Category.joins(:level).where(Level.arel_table[:description].lteq('Medium'))
davidrac
  • 10,723
  • 3
  • 39
  • 71
  • I am getting this error ActiveRecord::ConfigurationError: Association named 'levels' was not found; perhaps you misspelled it?. Level has_many category and category belongs_to Level – user588324 May 14 '13 at 20:03
  • What is this arel_table and lteq in here? is the any documentation for this? – user588324 May 14 '13 at 20:26
  • http://stackoverflow.com/questions/5688386/where-can-i-find-good-arel-documentation – davidrac May 14 '13 at 21:03