私は単純なポリモーフィックな関連性を持っています
#comment.rb
belongs_to :commentable, :polymorphic => true
has_many :comments, :as => :commentable
#post.rb
has_many :comments, :as => :commentable
accepts_nested_attributes_for :comments, :allow_destroy => true
したがって、IRBでは、Post.commentsまたはComment.commentsを実行できます。
しかし、どうすれば親の投稿を見つけることができますか?
Comment.postのように?
私は現在、一連の.commentable
'を実行することでそれらを取得できます。例えば :
Comment.find(1).commentable.commentable
=> Post(:id => ...