Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I'm trying to convert this has_many from using :finder_sql to using :select and :conditions so that
- # I can use :include with it. Is there any way to FORCE the query rails generates to not append
- # that first AND????
- EVENT_LIMIT = '20'
- RECENT_EVENTS_CONDITION =
- 'OR (actor_type = \'User\'
- AND actor_id IN (SELECT friend_id
- FROM relationships
- WHERE relationships.user_id = #{id} AND status=' + Relationship::ACCEPTED.to_s + ')'
- has_many :recent_events_of_interest,
- :as => :subject,
- :class_name => "TimelineEvent",
- :select => 'timeline_events.*',
- :conditions => [RECENT_EVENTS_CONDITION],
- :order => 'timeline_events.created_at DESC LIMIT ' + EVENT_LIMIT
- # This is the query that is generated... What I need is basically where I (the user) am the subject OR where
- # one of my friends is the actor.
- SELECT timeline_events.*
- FROM `timeline_events`
- WHERE (`timeline_events`.subject_id = 5 AND `timeline_events`.subject_type = 'User' AND (OR (actor_type = 'User'
- AND actor_id IN (SELECT friend_id
- FROM relationships
- WHERE relationships.user_id = 5 AND status=0))) ORDER BY timeline_events.created_at DESC LIMIT 20
Add Comment
Please, Sign In to add comment