elight / acts_as_commentable_with_threading

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments
MIT License
671 stars 168 forks source link

Problem handlind inheritence #30

Closed malev closed 11 years ago

malev commented 12 years ago

I have 2 models: Item and Book, where Book inherits from Item. Then if I do this:

71.9.3p194 :001 > i = Item.first 1.9.3p194 :002 > i.comment_threads Comment Load (1.8ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = 17 AND "comments"."commentable_type" = 'Item' => [#<Comment id: 44, commentable_id: 17, commentable_type: "Item", title: "", body: "primer", subject: "", user_id: 2, parent_id: nil, lft: 7, rgt: 8, created_at: "2012-05-13 15:31:38", updated_at: "2012-05-13 15:31:38">, #<Comment id: 45, commentable_id: 17, commentable_type: "Item", title: "", body: "segundo", subject: "", user_id: 2, parent_id: nil, lft: 9, rgt: 10, created_at: "2012-05-13 15:31:42", updated_at: "2012-05-13 15:31:42">, #<Comment id: 46, commentable_id: 17, commentable_type: "Item", title: "", body: "tercero", subject: "", user_id: 2, parent_id: nil, lft: 11, rgt: 12, created_at: "2012-05-13 15:31:46", updated_at: "2012-05-13 15:31:46">] 1.9.3p194 :003 > i.comments_ordered_by_submitted Comment Load (1.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = 17 AND "comments"."commentable_type" = 'Book' ORDER BY created_at DESC => [] 1.9.3p194 :004 >

As you can see, the first query use "Item" as commentable_type and the second uses "Book". The should both use the same or not?

elight commented 11 years ago

I'm pretty sure that just ActiveRecord's default behavior for polymorphic associations.