Re: [Rails] Learning Rails, how to walk through relations in template?

2014-09-16 Thread Colin Law
On 16 September 2014 18:22, frocco 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? There is usually no need to

Re: [Rails] Learning Rails, how to walk through relations in template?

2014-09-16 Thread frocco
Thank you, got it working. On Tuesday, September 16, 2014 1:27:27 PM UTC-4, Vivek Sampara wrote: > > Please look into this > http://apidock.com/rails/ActiveRecord/QueryMethods/includes > > On Tue, Sep 16, 2014 at 10:52 PM, frocco > > wrote: > >> Hello, >> >> I have a products table that is relat

Re: [Rails] Learning Rails, how to walk through relations in template?

2014-09-16 Thread Jason Fleetwood-Boldt
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 re

Re: [Rails] Learning Rails, how to walk through relations in template?

2014-09-16 Thread Vivek Sampara
Please look into this http://apidock.com/rails/ActiveRecord/QueryMethods/includes On Tue, Sep 16, 2014 at 10:52 PM, frocco 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? > > On

[Rails] Learning Rails, how to walk through relations in template?

2014-09-16 Thread frocco
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 Group