jackdempsey / acts_as_commentable

The ActiveRecord acts_as_commentable plugin
http://juixe.com/svn/acts_as_commentable/
MIT License
834 stars 176 forks source link

calling recent generates wrong query #22

Closed mabid closed 10 years ago

mabid commented 12 years ago

When calling project.comments.recent the following query is generate

SELECT comments.* FROM comments WHERE comments.commentable_id = 119 AND comments.commentable_type = 'Project' ORDER BY created_at ASC, created_at DESC

Why does it add ORDER_BY ASC before adding DESC.

if we call project.comments without any scope it generates following query

SELECT comments.* FROM comments WHERE comments.commentable_id = 119 AND comments.commentable_type = 'Project' ORDER BY created_at ASC

nwwatson commented 12 years ago

@mabid there is really a simple fix to this problem. The generator creates a default_scope in the Comment model that orders the comments in ascending order. Remove the default_scope in the comments model and anywhere where you need to ensure the order is in ascending order, you should use the in_order scope like:

model.comments.in_order

ridget commented 10 years ago

@jackdempsey can this issue also be closed as #30 was merged in?

jackdempsey commented 10 years ago

Yep, closing this as well