Topic: Merge Queries

Hi,
i would like to build an activity feed on my site. i setup a model Activity. the issue is that i would like to do 2 specific queries and merge them into one "feed".

Activity
ID | USER_ID | ACTIVITY_TYPE | DESCRIPTION


//get all activities for user 1,2,3, any ACTIVITY_TYPE
activities = Activity.where(:user_id => [1,2,3])

//get activities for user 4, only ACTIVITY_TYPE = 1
activities_per_user = Activity.where(:user_id => 4, :activity_type => 1)

//merge
how can i merge both queries into one array, sort by date and still do pagination with will_paginate?

thanks!

pete

Re: Merge Queries

1.AND search
Article.where('title like ?', "%rails%").where('title like ?', "%ruby%").page(params[:page])
  OR serach
Article.where('title like ? OR title like ?', "%rails%","%ruby%").page(params[:page]))

i am a rails rookie

Re: Merge Queries

2.set the attribute CONDITION of will_paginte
@Article = Article.paginate  :page = params[:page],:conditions => ['title like ? OR title like ?',"%ruby%","%rails%"], :per_page => 10

i am a rails rookie

Re: Merge Queries

3.use "paginate_by_sql",I think it's the best way,it's flexible
sql_sentence = "select * from Article where .....order by ...."
@Article =Article.paginate_by_sql(sql_sentence,:page => params[:page],:per_page => 10 )

i am a rails rookie

Re: Merge Queries

choose the way suit for you,hope that help

i am a rails rookie