sti and polymorphic's

Posted by Alexey Poimtsev on Stack Overflow See other posts from Stack Overflow or by Alexey Poimtsev
Published on 2010-04-08T21:31:20Z Indexed on 2010/04/08 21:33 UTC
Read the original article Hit count: 248

Hi, I have problem with my code

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

And on attempt go get comments for some NewsArticle i see in logs something like

  Comment Load (0.9ms)   SELECT "comments".* FROM "comments" WHERE ("comments"."commentable_id" = 1 and "comments"."commentable_type" = 'Post') ORDER BY created_at

Strange that "commentable_type" = 'Post'. Whats wrong?

PS: Rails 2.3.5 && ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord