undefined method `selector' for #<ActiveRecord::Relation:0xbb8710c> when using mongoid to save a record

StackOverflow https://stackoverflow.com/questions/15004645

문제

undefined method `selector' for #<ActiveRecord::Relation:0xbb8710c>

I am getting this error while trying to execute the follwoing code:

c = Content.first
c.is_processed = true
c.save # or c.update_attributes(:is_processed => true)

My Content model looks like this:

class Content
  include Mongoid::Document

  field :username 
  field :name
  filed :is_processed, :type => Boolean

  belongs_to :language
  has_many :translations    
end

I am using Mongoid 2.4, bson_ext 1.5, Ruby 1.9.2, Rails 3.2.5

도움이 되었습니까?

해결책

I found the mistake. My Content model had this line:

has_many :translations

I had migrated the content model from ActiveRecord to Mongoid. But, all the other tables are still in ActiveRecord. The has_many was referring to a ActiveRecord model. This caused the issue. I commented the line and now update is working fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top