1

I'm using Rails 4.1 with mongoid 4.0 Currently, I have a relation 1-N

class Tenant
  include Mongoid::Document
  belongs_to :tenant, index: true
end

class Experience
  include Mongoid::Document
  has_many :experiences, dependent: :nullify
end

I want to change this relationship to a N-N. For that I change in both models to:

class Tenant
  include Mongoid::Document
  has_and_belongs_to_many :tenants, index:true
end

class Experience
  include Mongoid::Document
  has_and_belongs_to_many :tenants, index:true
end

But now I don't have the former data I had.

hcarreras
  • 4,442
  • 2
  • 23
  • 32

1 Answers1

0

I ended up doing on the console something like:

e = Experience.last
e.tenant_ids = [e.attributes[:tenant_id]]

For all the experiences.

hcarreras
  • 4,442
  • 2
  • 23
  • 32