【发布时间】:2011-12-19 00:19:18
【问题描述】:
注意:我是 4 周大的编程人员。我的 Neighborhood 和 Cta_train 模型之间的 has_many :through => 关系有问题。
这是我的模型:
class CtaTrain < ActiveRecord::Base
belongs_to :Ctaline
has_and_belongs_to_many :searches
has_many :neighborhoods, :through => :CtaLocation, :foreign_key => :neighborhood_id
has_many :CtaLocations
end
class Neighborhood < ActiveRecord::Base
has_many :geopoints
has_many :listings
has_many :properties
has_and_belongs_to_many :searches
has_many :CtaTrains, :through => :CtaLocation, :foreign_key => :cta_train_id
has_many :CtaLocations
end
class CtaLocation < ActiveRecord::Base
belongs_to :neighborhood
belongs_to :CtaTrain
end
当我尝试这样做时:
neighborhood.CtaTrains
我收到此错误:
ActiveRecord::HasManyThroughAssociationNotFoundError(在模型 Neighborhood 中找不到关联 :CtaLocation):
我已经为此苦苦挣扎了几个小时......我已经尝试了许多来自stackoverflow的想法迭代......我上面展示的感觉像是最接近的解决方案,但显然仍然无法正常工作。任何想法将不胜感激!
【问题讨论】:
标签: ruby-on-rails activerecord has-many-through