Ruby on Rails
Tuesday, September 16, 2014
As described here http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations
I think what you want is something like
products = Product.includes(:category)
This will eager load the category association when you load the Product objects. You must specify the inverse relationship (in product.rb you must have belongs_to :category) for this to work.
On Sep 16, 2014, at 1:22 PM, frocco <farocco@gmail.com> wrote:
Hello,
I have a products table that is related to category.
category has many products.
How do I query the products to also include the category?
Once I do this, how to I show the category data in my template?
Thanks--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ef128a6d-5b7b-412f-b8ca-db77ccbff2c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment