Rails - How do I write this string condition as an array condition -
named_scope :correct, :include => :correction, :conditions => "checked_at not null , corrections.id null"
on side note have googled loads , looked through books cant seem find list of various types of conditions can use , how differ when implenting them strings, arrays or hashes.
is there list of syntax anywhere?
the string posted correct. also, there's no way express same condition using arrays or hashes.
array–syntax , hash-syntax useful when need interpolate values. instance, following condition
named_scope :is_one, :conditions => "field = '1'"
can written as
named_scope :is_one, :conditions => ["field = ?", "1"]
or
named_scope :is_one, :conditions => { :field => "1" }
the hash-syntax subset of array-syntax , supports limited set of operators. instance, can transform
named_scope :is_one, :conditions => ["field1 = ? , field2 in (?)", "1", ["foo", "bar"]]
into
named_scope :is_one, :conditions => { :field1 => "1", :field2 => ["foo", "bar"] }
but there's no hash-equivalent for
# or named_scope :is_one, :conditions => ["field1 = ? or field2 in (?)", "1", ["foo", "bar"]] # <> named_scope :is_one, :conditions => ["field1 <> ?", "1"]
Comments
Post a Comment