开发者

Querying for an Unrelated model field

开发者 https://www.devze.com 2023-04-06 14:29 出处:网络
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 mo

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

精彩评论

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