Rails ActiveRecord查询抛出undefined BelongsToAssociation错误

时间:2011-03-20 20:07:55

标签: ruby-on-rails activerecord associations

我有一个包含belongs_to关联版本的Rails 2.3模型出版物。当我运行这个activerecord时,它第一次发现它有效,但是刷新页面会为#< ActiveRecord :: Associations :: BelongsToAssociation:0x10cb2a338>`提供这个错误undefined method版本'。

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

0 个答案:

没有答案