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 3878392
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:36:27+00:00 2026-05-19T22:36:27+00:00

Rails v3.0.3 Original schema has customers table, and the app has data for 100

  • 0

Rails v3.0.3
Original schema has customers table, and the app has data for 100 customers.

via migration we add cust_info table with 1:1, eg:

customers has_one cust_info 
cust_info belongs_to customers

so right now (after running rake db:migrate to create the new model) we have 100 ‘old’ customer records that do not have the 1:1 required cust_info record.

QUES (1a) (legacy data update) what is the “rails way” to generate the required (empty) cust_info record for each of our 100 existing customer records?

QUES (2) (going forward) how to we modify our app so when we create a NEW customer record it will automatically create an associated cust_info record at the same time?

  • 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-19T22:36:28+00:00Added an answer on May 19, 2026 at 10:36 pm

    Q1: Because you’ve a small dataset, I’d work in the console:

    Customer.all.each do |c|
       c.create_cust_info.save
    end
    

    Q2: use the following callback: after_create in your customer model and build the cust_info inside

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Basic Goal A Rails app that can load new content via Ajax while
In my Rails application there is a model that has some has_one associations (this
Rails 3.0.3 ruby 1.9.2p0 The Problem: I have a Users table which has many
Newbish AWS question: Our Rails app currently allows image uploads via Carrierwave to an
Rails has a nice idiom that makes it easy for you to have a
Rails has no way of creating foreign keys in migrations (there are plugins to
Rails has the rest autho plugin which works well but is there a solution
I have a simple messaging system in Rails with a Message table for the
I have a Rails project that is basically a simple web app for a
I'm maintaining a rails 2.1 application that has some unfortunate choices for column names.

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.