无效的源反射宏:的has_many:通过 [英] Invalid source reflection macro :has_many :through
问题描述
我有这样的愤怒协会:融资> - 事件> - 子程序> - 程序。我想通过他们都获得查看在程序last_financings因此code是:
I have such angry associations: financings >- events >- subprograms >- programs. I want to get acces to last_financings from programs through all of them so code is:
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功能我得到这个错误
So when I want to access to subprogram_last_actual_financings in after_initialize function I get this error
Invalid source reflection macro :has_many :through for has_many :subprogram_last_actual_financings, :through => :fcp_subprograms. Use :source to specify the source reflection.
但我有:在我的联想源的选择。我究竟做错了什么?
but I have :source option in my associations. What am I doing wrong?
推荐答案
你得到的错误是关于source_reflection是无效的关联,因为源的has_many通过必须是belongs_to的,HAS_ONE或无的has_many通过选项。所以你不能使用:last_actual_financings作为源
The error you get is about source_reflection is an invalid association, because source for has_many through must be belongs_to, has_one or has_many without through option. So you can't use :last_actual_financings as a source.
这篇关于无效的源反射宏:的has_many:通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!