0
我想以軌道方式加入我的表。紅寶石onrails加入表
這是SQL查詢
SELECT * FROM `ads` left join `state` ON ads.state_id = states.id
我想以軌道方式加入我的表。紅寶石onrails加入表
這是SQL查詢
SELECT * FROM `ads` left join `state` ON ads.state_id = states.id
Rails guides是你的朋友=)
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")