I have two similar tables in rails named as messages and message_histories. Periodically we remove the old data from messages table and drop it in message_histories .
Now , I want to generate a report on the count of messages grouped by app_id which is present in message and message_history table .
Is there a way to Query [Message & MessageHistory ] Model and paginate on the records .
Currently I use the following Step , It looks weird but suggest a better way to do this :
@messages = Message.select("SUM(devices_count) as count ,CAST(run_at AS DATE) AS date").where(:app_id => @app.id).where("last_run_date is not ?", nil).group("CAST(run_at AS DATE)").order("date desc")
@messages << MessageHistory.select("SUM(devices_count) as count ,CAST(run_at AS DATE) AS date").where(:app_id => @app.id).where("last_run_date is not ?", nil).group("CAST(run_at AS DATE)").order("date desc")
@messages = @messages.flatten.paginate(:page => params[:page] || 1, :per_page => 100)