Anyone knows how to do left join as well as inner join in same query.

2 views
Skip to first unread message

Sandip Ransing

unread,
Jun 3, 2009, 3:19:54 AM6/3/09
to rubyonra...@googlegroups.com
Hello All,

Is rails supporting left and inner joins in same query ??
I dont wanted to do it using find_by_sql.

I have model having belongs_to and has_one associations.

I wanted to something like......

Model.find ( :all, left join on belongs_to model and inner join  on has_one model, :select =>. "some attributes from all models" )

Thanks for help !

Sandip
--
Ruby on Rails Developer
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com

Andrew Timberlake

unread,
Jun 3, 2009, 3:27:07 AM6/3/09
to rubyonra...@googlegroups.com

Check the docs at
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002208

use :joins to include join SQL syntax
:joins => 'inner join x outer join y'

Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

Sandip Ransing

unread,
Jun 3, 2009, 5:37:42 AM6/3/09
to rubyonra...@googlegroups.com
Thanks !
Reply all
Reply to author
Forward
0 new messages