Reputation: 231
Admin Model:
has_many :transport_vehicles_as_driver, class_name: "Transport::Vehicle",as: :driver
has_many :transport_vehicles_as_attendant, class_name: "Transport::Vehicle",as: :attendant
relation_1 = Admin.where(category: "TRANSPORT").left_outer_joins(:transport_vehicles_as_attendant).where("transport_vehicles.reference_code LIKE ?", "%#{keyword}%").distinct
relation_2 = Admin.where(category: "TRANSPORT").left_outer_joins(:transport_vehicles_as_driver).where("transport_vehicles.reference_code LIKE ?", "%#{keyword}%").distinct
relation_1.or(relation_2) produces the following error:
ArgumentError (Relation passed to #or must be structurally compatible. Incompatible values: [:left_outer_joins])
I have checked the following close stackoverflow sources : Relation passed to #or must be structurally compatible. Incompatible values: [:references]
Upvotes: 2
Views: 265
Reputation: 231
Admin.where(category: "TRANSPORT").
joins("LEFT JOIN transport_vehicles ON
(transport_vehicles.driver_id = admins.id) OR (transport_vehicles.attendant_id = admins.id)").
where("transport_vehicles.reference_code LIKE ?", "%#{keyword}%").distinct
Upvotes: 1