parm530
4/4/2018 - 3:49 PM

Query Methods

Example usage of query methods

Query Methods

  • returns an ActivRelation object to enable method chaining!
#where(conditions)
subject = Subject.where(visible: true)

#Daisy chaining
subject = Subject.where(visible: true),order("position ASC")

#want to see the SQL that got generated?
subject.to_sql

Condition Expression Types

  • To be passed in to the where clause
  • strings: name = "first subject" AND visible = true
    • flexible and raw
    • be careful with SQL injections (don't use variable name! "name = "#{name_var}"")
  • array
    • ["name = ? AND visible = true", "first subject"]
  • hash: {:name => 'first subject', :visible = true}