Ich habe Probleme mit meinem CodeSTI und Polymorphe
class Post < ActiveRecord::Base
end
class NewsArticle < Post
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at'
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true, :counter_cache => true
end
Und Versuch zu holen Kommentare für einige Newsartikel i in Protokollen etwas sehen, wie
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE ("comments"."commentable_id" = 1 and "comments"."commentable_type" = 'Post') ORDER BY created_at
Seltsam, dass "commentable_type" = ‚Beitrag '. Was ist los?
PS: Schienen 2.3.5 & & rubin 1.8.7 (2010-01-10 Patchlevel 249) [i686-darwin10]
huh ... Tabellenname ist korrekt, aber STI-Modellname ist falsch –
Für die polymorphe Beziehung ist nur die Tabelle wichtig, sobald die Tabelle geladen ist, kann der Vererbungstyp bestimmt werden. – danivovich