Querying for an Unrelated model field
I'm a newbie on rails. How to query for a non related model field. Say I'v开发者_Python百科e a billing model where I need to fetch the product group while I store only product_code in the billing model. I'm using acts as api. I need to send all product_codes along with product group which is not at all related to billing model.
Thank You Sai
Consider,
Billing.each do |r|
product = Product.find(r.billing_item)
product_group = product.product_group
end
Of course product_group
above would be an AR association, you'd need to grab whatever appropriate attribute of your ProductGroup, i.e. name or title for example.
精彩评论