Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord test Greater/Lesser Than inside Hash Condition

The Question: Is it possible to test within a hashed condition if an attribute of a joined table is greater/lesser than a value

An example: test if actors age is greater than ageVariable:

  • Is it possible to write instead of the ARRAY CONDITION:

    ageVariable = 36<br> Movie.includes(:actors).where("actors.age > ?", ageVariable)
    
  • The HASH CONDITION something like:

    ageVariable = 36
    Movie.includes(:actors).where(:actors => { :age => COMPARE_LOGIC })
    # Where COMPARE_LOGIC is something like: (:age > ageVariable)
    
like image 572
BARJ Avatar asked May 17 '13 13:05

BARJ


1 Answers

http://guides.rubyonrails.org/active_record_querying.html#hash-conditions

Only equality, range and subset checking are possible with Hash conditions.

like image 134
deepthi Avatar answered Sep 18 '22 16:09

deepthi