0

I am using the acts_as_network gem which allows me to get all the friends for a User through 'User.friends'

I want to create a 'friend feed' showing all the recent events for all of the friends by searching through the Event records where Event:

  Event  | giver_id | receiver_id | date |

Conceptually I'd like to be able to do this:

feed = Events.giver_id_or_receiver_id_in(User.friends).date_gt(Date.today.2.weeks.ago)

This should give me an array of all events where either the giver_id or receiver_id is IN the array of friends (User.friends), created in the last two weeks.

How can I do this?

Satchel
  • 16,414
  • 23
  • 106
  • 192

1 Answers1

0

IN queries can be done with: where(:giver_id => array)

So I think you can do something like:

scope :party_in, lambda {|friends| where(:giver_id => friends) | where(:receiver_id => friend) }

You can then chain the scope with the rest of your query:

feed = Events.party_in(User.friends).date_gt(Date.today.2.weeks.ago)
DGM
  • 26,629
  • 7
  • 58
  • 79
  • is this using metawhere instead of rd_searchlogic? And I use 'friend' or 'friends'? tx – Satchel Mar 26 '11 at 04:19
  • btw, User.friends isn't an array of *just* ID's (e.g. ["1", "2", "3"]) it is the array representing actual Users.... – Satchel Mar 26 '11 at 04:22
  • Oh, yeah, that's metawhere, sorry. If User.friends doesn't automatically call to_param on it, you could do User.friends.map(&:id) – DGM Mar 27 '11 at 01:06