Hello,
I'm trying to join 2 tables with ruby on rails 3.2.
rails generate model product name:string
rails generate model price product_id:integer price:integer
date:datetime
product.rb:
class Product < ActiveRecord::Base
has_many :prices
end
price.rb:
class Price < ActiveRecord::Base
belongs_to :product
end
What is the most efficient way to get all products including the latest
price into the View.
Some tries didnt work for this:
@test = Product.includes(:prices).all
I didnt find anything about the prices in @test.
Thanks for help!
Fabian
--
Posted via http://www.ruby-forum.com/.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment