A
A
Anton Ipatov2019-12-03 11:45:10
Ruby on Rails
Anton Ipatov, 2019-12-03 11:45:10

Transferring data from one model to another?

Hello, I'm using Ruby on Rails 5.2.3 and Mongoid 7.0
. I need to migrate :name and :image_url from User.rb to Profile.rb and there are empty fields in some posts, they don't need to be migrated.
User.rb

class User
  include Mongoid::Document

  field :name, type: String
  field :image_url, type: String

  has_many :profiles, dependent: :destroy
end

Profile.rb
class Profile
  include Mongoid::Document

  field :name, type: String
  field :image_url, type: String

  belongs_to :user, touch: true
end

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question