When I do such a query, AR misses the second 1/2 of the where clause
(assigned_product_id):
XpRawBillDetailProduct.joins(:xp_raw_bill_detail).where(“xp_raw_bill_details.account_subcode_id=#{
account_subcode.id}”, :assigned_product_id =>
raw_bill_product.assigned_product_id).to_sql
“SELECT “xp_raw_bill_detail_products”.* FROM
“xp_raw_bill_detail_products” INNER JOIN “xp_raw_bill_details” ON
“xp_raw_bill_details”.“id” =
“xp_raw_bill_detail_products”.“xp_raw_bill_detail_id” WHERE
(xp_raw_bill_details.account_subcode_id=11)”
I have found I can get around this by using two wheres:
(rdb:1)
XpRawBillDetailProduct.joins(:xp_raw_bill_detail).where(“xp_raw_bill_details.account_subcode_id=#{
account_subcode.id}”).where(:assigned_product_id =>
raw_bill_product.assigned_product_id).to_sql
“SELECT “xp_raw_bill_detail_products”.* FROM
“xp_raw_bill_detail_products” INNER JOIN “xp_raw_bill_details” ON
“xp_raw_bill_details”.“id” =
“xp_raw_bill_detail_products”.“xp_raw_bill_detail_id” WHERE
(xp_raw_bill_details.account_subcode_id=11) AND
(“xp_raw_bill_detail_products”.“assigned_product_id” = 107)”
(rdb:1)
But is there a prettier way to mix inside a single where? Seems wrong
the
way I am doing it.