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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 21, 5:19 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> 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_detail s.account_subcode_id=#{ > account_subcode.id}", :assigned_product_id => > raw_bill_product.assigned_product_id).to_sqlIf you do this, AR assumes that the hash you provided is a map for substituting named bind variables (ie if your query contained " AND assigned_product_id = :assigned_product_id" it would replace :assigned_product_id with the value from the hash Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Mar 21, 2011 at 11:29 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Mar 21, 5:19 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > 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_detail > s.account_subcode_id=#{ > > account_subcode.id}", :assigned_product_id => > > raw_bill_product.assigned_product_id).to_sql > > If you do this, AR assumes that the hash you provided is a map for > substituting named bind variables (ie if your query contained " AND > assigned_product_id = :assigned_product_id" it would > replace :assigned_product_id with the value from the hash >Thanks Fred, makes sense.> > Fred > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.