Wanderwelten wrote: > Hey everyone, > > i can't build AR-Queries with relationships between tables. Here's a > short sample: > > class Customer < ActiveRecord::Base > has_many :projects > end > class Project < ActiveRecord::Base > belongs_to :customer > end > When I execute the following Code in my Controller: @customers = > Customer.all.includes(:projects) > a NoMethodError (undefined method `includes' for #<Array:0xb679e030>) > is thrown. > > Why did i receive an Array and not an Object of the class > ActiveRecord? > > Thanks in advance for your help! > > Greets, Gerrit
Calling .all performs the query and returns the array. You need to put the includes() statement before the .all (and you actually don't need the all anyway, it'll know to load all of them unless you supply a limit, conditions, etc.) -- 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 post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.