Hallo Michael,
hier mein Lösungsvorschlag:
class Person < ActiveRecord::Base
has_many :films
has_many :roles, :through => :films, :uniq => true
end
class Film < ActiveRecord::Base
belongs_to :person
belongs_to :role
end
class Role < ActiveRecord::Base
has_many :films
has_many :people, :through => :films
end
Das sind alle Modelle die ich benötige.
Role entspricht den von Dir definierten Rollentypen
p = Person.find_by_name('Clint Eastwood')
Jetzt kannst ich alle Filme abfragen in welchen Clint Eastwood z.B.
als Schauspieler mitgespielt hat:
p.roles.find_by_name('Schauspieler').films
oder
p.films.all(:conditions => ['role_id = 1']) falls die Rolle
'Schauspieler' die id = 1 hat.
Die zweite Abfrageform sieht nicht so elegant aus ist aber schneller
in der Ausführung.
Gruss,
Roman
Am 08.03.2009 um 01:11 schrieb Michael Schuerig:
in denen sie mitgespielt hat.
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug