Skip to content

Instantly share code, notes, and snippets.

@meltzerj
Created May 7, 2011 08:11
Show Gist options
  • Select an option

  • Save meltzerj/960309 to your computer and use it in GitHub Desktop.

Select an option

Save meltzerj/960309 to your computer and use it in GitHub Desktop.
has_many :user_notifications
NOTIFICATIONS_CONDITION = '(actor_type = \'User\' AND ((secondary_subject_type = \'Video\' AND secondary_subject_id IN (SELECT id FROM videos WHERE user_id = #{id})) OR (secondary_subject_type = \'User\' AND secondary_subject_id = #{id})))'
has_many :notifications, :through => :user_notifications,
:finder_sql => 'SELECT timeline_events.* FROM timeline_events
WHERE ' + NOTIFICATIONS_CONDITION + '
ORDER BY timeline_events.created_at DESC'
belongs_to :user
belongs_to :notification, :classname => 'TimelineEvent'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment