开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜