Top > Ruby on Railsあれこれ > findメソッドの:includeオプションの書き方
  0
  1
  2
class Address < ActiveRecord::Base
  has_many :employees
end
  0
  1
  2
  3
class Employee < ActiveRecord::Base
  belongs_to :department, :foreign_key => 'department_id'
  belongs_to :address, :foreign_key => 'address_id'
end
  0
  1
  2
  3
class Department < ActiveRecord::Base
  has_many :employees
  belongs_to :hoge
end
  0
  1
  2
class Hoge < ActiveRecord::Base
  has_one :department
end
  0
Employee.find(:all, :include => :department)
  0
Address.find(:all, :include=> {:employees => :department})
  0
Employee.find(:all, :include=> [:department, :address])

  0
Employee.find(:all, :include=> [{:department => :hoge}, :address])
  0
Employee.find(:all, :include=>:department)
  0
Employee.find(:all, :include=>:department, :order => "departments.name" )

添付ファイル: fileinclude_option_1.jpg 534件 [詳細]

リロード   新規 編集 凍結 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012-08-08 (水) 23:25:36 (2925d)