I'm running into an issue with an existing ActiveRecord::Observer model that records various Activities of a User the site. Everything was working really well, until I tried to observe the User class with the same Activity model that it uses to observe other models. Consider that:
class Activity < ActiveRecord::Base
belongs_to :user
belongs_to :item, :polymorphic => true
end
class ActivityObserver < ActiveRecord::Observer
observe :billing, :call, :vanity_number
end
class User < ActiveRecord::Base
has_many :comments
has_many :activities
end
class Comment < ActiveRecord::Base
belongs_to :user
has_many :activities, :as => :item
end
The above worked fine. A query for User.activities would return rows of Comment Activities. As soon as I added :user to the observe method in ActivityObserver and changed has_many :activities in the User model to has_many :activities, :as => :item, User.activities would only return rows that were activities pertaining to that User instance and not any Comments
Why is this? What can I do to get this working as expected?