How to build scope for count() & has many polymorphic?

Hello, i have the following models in my application:

class Message < ActiveRecord::Base
has_many :comments, :as => :commentable, :dependent => :destroy,
:order => ‘created_at ASC’
end

class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end

I need “commented” named scope, which do the follownig thing:

Message.commented -> returns all messages where comments is > 0.

How i can do this?

anybody knows?

The typical way around this is to turn on counter caching
for :comments, and filter against that.

–Matt J.

On Jul 22, 8:18 am, Joao S. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs