Rails4 ActiveRecordã§orã使ç¨ãã
whereã§ORã使ç¨ããã®ã§ãã¡ã¢ã
Userã«class1_idãclass2_idãclass3_idããããããã«ã¯Classã®idãç»é²ãããã®ã¨ããã
class1_idãclass2_idãclass3_idã®ã©ããã1ã§ããã¦ã¼ã¶ã¼ãæ¢ãããã
class1 = User.where(:class1_id => 1) class2 = User.where(:class2_id => 1) class3 = User.where(:class3_id => 1) class1 = class1.where_values.reduce(:and) class2 = class2.where_values.reduce(:and) class3 = class3.where_values.reduce(:and) @users = User.where(class1.or(class2).or(class3))
åèï¼
sql - ActiveRecord Arel OR condition - Stack Overflow