追記: すみません、join時だけでなく通常のfindでも使えるようです。
関連するモデルからデータを引くときに、↓のように:joinsオプションを使うことはよくあります。
1 2 3 4 5 6 7 8 9 10 11 | class Article < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :articles end # Get all the users that have published articles User.find(:all, :joins => :article, :conditions => ["articles.published = ?", true]) |
今回のコミットでは、join時での:conditionsオプションをハッシュで指定できるようになりました。
1 2 3 | # Get all the users that have published articles User.find(:all, :joins => :article, :conditions => { :articles => { :published => true } }) |
綺麗に書けますが、これ使うかなあ。。

