Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:33:09+00:00 2026-05-18T08:33:09+00:00

Suppose I have two models A and B Now I want to copy some

  • 0

Suppose I have two models A and B

Now I want to copy some information from an instance of A to an instance of B by clicking a button

Is there a way of doing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:33:09+00:00Added an answer on May 18, 2026 at 8:33 am

    This process is called cloning an object and the complexity of it depends on what kind of information you would like to clone.

    If you simply want to clone an object’s fields, you would do something like this:

    old_object = A.find(old_object_id)
    new_object = B.new
    
    new_object.field_one = old_object.field_one
    new_object.field_two = old_object.field_two
    new_object.save!
    

    If, however, you want to also clone the old object’s associations, you will need to do that by hand.

    Say for the sake of argument that A had a has_many association of B objects called bees, and B has_many C objects called sees, this could get a little complex:

    old_object.bees.each do |bee|
       new_bee = bee.clone
       new_bee.sees.each do |see|
          new_see = see.clone
          new_see.save!
       end
       new_object.bees.push(new_bee)
    end
    new_object.save!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So suppose I have two Models -- Project and Task I want user to
Suppose I have two models, Book and Page, such there is a one-to-many relationship
Suppose I have two h:inputText components. I want to bind both of the text
I have two models I want to connect with an m-to-m relationship, but I
Suppose I have two models, A and B , where an A can have
I'm investigating on how validates_presence_of actually works. Suppose I have two models class Project
Suppose we have two variables that we wish to build a model from: set.seed(10239)
Suppose you have two models, User and City, joined by a third model CityPermission:
Suppose we have two models, Task and User. So a user can have many
suppose I have a model and a view ,ths view have two method:one is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.