Hallo,

ich hänge da jetzt schon seit Stunden dran und komme nicht weiter. Das ganze 
ist unter Rails 3.0.3.

Ich habe ein Model namens Product, das so aussieht:

class Product < ActiveRecord::Base

  has_many :authors, :through => :works
  has_many :works

end

Und dann gibts da noch das ensprechende Author- und Works-Model.

Bei der Ausgabe der Produktliste sollen auch die jeweiligen authors angezeigt 
werden. Ist prädestiniert für eager loading.

So habe ich die includes angelegt:

@products = Product.includes(:authors)


Wenn ich die Action ausführe, dann findet dieser Aufruf einmal statt:

Product Load (0.5ms)  SELECT `products`.* FROM `products` LIMIT 10
  Work Load (2.3ms)  SELECT `works`.* FROM `works` INNER JOIN `authors` ON 
`authors`.`id` = `works`.`author_id` WHERE (`works`.product_id IN 
(1,2,3,4,5,6,7,8,9,10)) ORDER BY works.role_type, authors.last_name, 
authors.first_name


… aber dann bei jeder Schleife:

Work Load (0.9ms)  SELECT `works`.* FROM `works` INNER JOIN `authors` ON 
`authors`.`id` = `works`.`author_id` WHERE (`works`.product_id = 2) ORDER BY 
works.role_type, authors.last_name, authors.first_name

Author Load (0.1ms)  SELECT `authors`.* FROM `authors` WHERE (`authors`.`id` = 
3) ORDER BY last_name, first_name


Ich hatte auch probiert die includes verschachtelt anzugeben, das hat aber auch 
nichts geändert:

@products = Product.includes(:works => :author)


Wie gesagt, ich steh' gerade vollständig auf dem Schlauch.

Viele Grüße

Michael Kastner
_______________________________________________
rubyonrails-ug mailing list
rubyonrails-ug@headflash.com
http://mailman.headflash.com/listinfo/rubyonrails-ug

Antwort per Email an