You are here: Forums Ask a Rails expert Integrating 2 ActiveRecord Obj...
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 0
Sign in to rate this post
|
I have two ActiveRecord Models where I want to use the find (:all, :order=>‘created_at DESC’) method (or sql) so it output a collection of both objects together listed in descending order by date. Does anyone have any ideas how to do this? |
Authority 12
Posting Rating 93
Sign in to rate this post
|
You could try something like this, wrapped into a method called first_and_next_collection defined on both of your models: FirstModel.find(:all).concat(NextModel.find(:all)).sort{|a,b| a.created_at <=> b.created_at} |
Authority 12
Posting Rating 95
Sign in to rate this post
|
Try using :include like FirstModel.find(:all, :include => :next_model, :order=>‘created_at DESC’) |
Ask a Rails expert : Sanitizing html
Ask a Rails expert : First post, requesting sage perspective
Ask a Rails expert : How to use mephisto
Ask a Rails expert : How to use mephisto
Ask a Rails expert : will_paginate customization problem
Ask a Rails expert : BackgroundRB still wants 'development' environment...?
Ask a Rails expert : activescaffold, sql exception
Ask a Rails expert : Passing non-english chars in query string
Ask a Rails expert : Rails and 2D barcodes
Ask a Rails expert : apache giving proxy error