1

私は次のモデルを持っています:

class Person < ActiveRecord::Base
  has_many :accounts, :through => :account_holders 
  has_many :account_holders
end

class AccountHolder < ActiveRecord::Base
  belongs_to :account
  belongs_to :people
end

class Account < ActiveRecord::Base
  has_many :people, :through => :account_holders 
  has_many :account_holders
end

ただし、この関係を使用すると問題が発生します。Account.first.account_holders は問題なく動作しますが、Account.first.people は以下を返します。

NameError: uninitialized constant Account::People
    from /Users/neil/workspace/xx/vendor/rails/activesupport/lib/active_support/dependencies.rb:105:in `const_missing'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/base.rb:2204:in `compute_type'
    from /Users/neil/workspace/xx/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/base.rb:2200:in `compute_type'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/reflection.rb:156:in `send'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/reflection.rb:156:in `klass'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:73:in `find_target'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:353:in `load_target'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:139:in `inspect'

何か案は?

4

2 に答える 2

7

belongs_to には単数形が必要です。でAccountHolder

belongs_to :person
于 2009-07-08T11:46:51.380 に答える