我有這樣的憤怒的協會:financings> - events> - subprograms> - programs。我想通過他們都獲得查看在程序last_financings這樣的代碼是:無效的源反射宏:has_many:通過
class Fcp < Program
has_many :fcp_subprograms,
:foreign_key => 'parent_id'
has_many :subprogram_last_actual_financings,
:through => :fcp_subprograms,
:source => :last_actual_financings
class FcpSubprogram < Program
belongs_to :fcp,
:class_name => 'Fcp',
:foreign_key => 'parent_id'
has_many :events,
:foreign_key => 'fcp_id'
has_many :last_actual_financings,
:through => :events,
:source => :last_actual_financings
class Event < ActiveRecord::Base
belongs_to :fcp,
:class_name => 'Fcp',
:foreign_key => 'fcp_id'
belongs_to :fcp_subprogram,
:class_name => 'FcpSubprogram',
:foreign_key => 'fcp_id'
has_many :last_actual_financings,
:class_name => 'ActualFinancing',
:order => 'date DESC',
:limit => 1
所以,當我想訪問subprogram_last_actual_financings在after_initialize功能我得到這個錯誤
Invalid source reflection macro :has_many :through for has_many :subprogram_last_actual_financings, :through => :fcp_subprograms. Use :source to specify the source reflection.
但我有:來源選項在我的協會。我究竟做錯了什麼?
你可以試試nested_has_many_through插件http://github.com/ianwhite/nested_has_many_through 使用rails-2.3分支,儘管它是實驗性的。我沒有嘗試過。 或者您可以使用finder_sql選項for has_many – 2009-12-21 09:51:46
有趣的插件!我必須試一試 – klew 2009-12-21 10:04:47
非常感謝您的建議! – Antiarchitect 2009-12-21 10:06:02