我正试图以rails方式加入我的桌子。
这是sql查询
SELECT * FROM `ads` left join `state` ON ads.state_id = states.id
答案 0 :(得分:0)
Rails guides是你的朋友=)
答案 1 :(得分:0)
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
Student.joins(:schools).where(:schools => { :type => 'public' })
Student.joins(:schools).where('schools.type' => 'public' )
或Rails ActiveRecord :joins with LEFT JOIN instead of INNER JOIN:
User.find(:all, :limit => 10,
:joins => "LEFT JOIN `user_points` ON user_points.user_id = users.id" ,
:select => "users.*, count(user_points.id)", :group =>
"user_points.user_id")
答案 2 :(得分:0)
如果您使用滑轨5,则可以使用此-
Ad.left_outer_joins(:states)