Using unions in ActiveRecord

I am at a complete loss of how to do this in an ActiveRecord:

Example

select concat(c.last_name, ', ', c.first_name,) as name
from customer c inner join basketball b on
(c.id=b.cust_id)
where b.start_date > ‘8/1/2007’
union
select concat(c.last_name, ', ', c.first_name,) as name
from customer c inner join football f on
(c.id=f.cust_id)
where b.start_date > ‘8/1/2007’
union
select concat(c.last_name, ', ', c.first_name,) as name
from customer c inner join soccer s on
(c.id=s.cust_id)
where b.start_date > ‘8/1/2007’
order by name

Any help would be greatly appreciated. Thanks.

find_by_sql :wink:

On 8/16/07, George P. [email protected] wrote:

select concat(c.last_name, ', ', c.first_name,) as name
Any help would be greatly appreciated. Thanks.

Posted via http://www.ruby-forum.com/.


Cheers!

So there is no way to use AR to do this? Or do I need to hack my own
solution…

Pratik Naik wrote:

find_by_sql :wink:

On 8/16/07, George P. [email protected] wrote:

select concat(c.last_name, ', ', c.first_name,) as name
Any help would be greatly appreciated. Thanks.

Posted via http://www.ruby-forum.com/.


Cheers!

To clarify, I know how to do this using find_by_sql. I figure I need to
use ActiveRecord because I need to pass parameters to the query, such as
the date field. I can’t find a way to pass a parameter using
find_by_sql.

Pratik Naik wrote:

find_by_sql :wink:

On 8/16/07, George P. [email protected] wrote:

select concat(c.last_name, ', ', c.first_name,) as name
Any help would be greatly appreciated. Thanks.

Posted via http://www.ruby-forum.com/.


Cheers!