Hi, hast du denn in der includes(:works => :author) Variante auch über .works iteriert anstatt über .authors?
Viele Grüße, Till Am 26.01.2011 um 12:47 schrieb rubyonrails...@galt.de: > 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 Till Schulte-Coerne, till.schulte-coe...@innoq.com, http://www.innoq.com innoQ Deutschland GmbH, Halskestr. 17, D-40880 Ratingen, Germany Phone: +49 2102 77162-100 Mobile: +49 1515 7132845 Fax: +49 2102 77160-1
PGP.sig
Description: Signierter Teil der Nachricht
_______________________________________________ rubyonrails-ug mailing list rubyonrails-ug@headflash.com http://mailman.headflash.com/listinfo/rubyonrails-ug