Rails ActiveRecord 查询抛出未定义的 BelongsToAssociation 错误
我有一个 Rails 2.3 模型出版物,其中包含 own_to 关联版本。当我运行此 activerecord 时,发现它第一次工作,但刷新页面时出现此错误 undefined method
version' for #
Publication.find(:all, :limit => 10, :order => "date_published desc",
:include => [:version => {:work => :work_type},
:products => {:media_type => :meaning} ])
class Publication < ActiveRecord::Base
acts_as_nested_set
belongs_to :imprint
has_many :products
has_many :subscriptions
belongs_to :cover_image
belongs_to :version
accepts_nested_attributes_for :products, :allow_destroy => true
accepts_nested_attributes_for :subscriptions, :allow_destroy => true
accepts_nested_attributes_for :cover_image, :allow_destroy => true
accepts_nested_attributes_for :version
end
class Version < ActiveRecord::Base
belongs_to :work
has_many(:authorships, :as => :authorable, :include => [:role])
has_many(:user_authorships, :as => :authorable,
:conditions => { :authorizable_type => "User" })
has_many(:organization_authorships, :as => :authorable,
:conditions => { :authorizable_type => "Organization" })
has_one :element, :class_name => "Element", :foreign_key => :version_id
has_many :tag_links, :as => :taggable, :class_name => 'TagLink'
has_many :tags, :through => :tag_links, :class_name => 'Tag'
accepts_nested_attributes_for :authorships, :allow_destroy => true
accepts_nested_attributes_for :work
end
I have the a Rails 2.3 model Publication that contains the belongs_to association version. When I run this activerecord find it works the first time but refreshing the page give me this error undefined method
version' for #<ActiveRecord::Associations::BelongsToAssociation:0x10cb2a338>`.
Publication.find(:all, :limit => 10, :order => "date_published desc",
:include => [:version => {:work => :work_type},
:products => {:media_type => :meaning} ])
class Publication < ActiveRecord::Base
acts_as_nested_set
belongs_to :imprint
has_many :products
has_many :subscriptions
belongs_to :cover_image
belongs_to :version
accepts_nested_attributes_for :products, :allow_destroy => true
accepts_nested_attributes_for :subscriptions, :allow_destroy => true
accepts_nested_attributes_for :cover_image, :allow_destroy => true
accepts_nested_attributes_for :version
end
class Version < ActiveRecord::Base
belongs_to :work
has_many(:authorships, :as => :authorable, :include => [:role])
has_many(:user_authorships, :as => :authorable,
:conditions => { :authorizable_type => "User" })
has_many(:organization_authorships, :as => :authorable,
:conditions => { :authorizable_type => "Organization" })
has_one :element, :class_name => "Element", :foreign_key => :version_id
has_many :tag_links, :as => :taggable, :class_name => 'TagLink'
has_many :tags, :through => :tag_links, :class_name => 'Tag'
accepts_nested_attributes_for :authorships, :allow_destroy => true
accepts_nested_attributes_for :work
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论