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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:15:29+00:00 2026-05-29T20:15:29+00:00

I have two spreadsheets of data saved in separate Google spreadsheets, Stores and Products.

  • 0

I have two spreadsheets of data saved in separate Google spreadsheets, Stores and Products.

Stores has columns for:

  • Store name
  • Store location
  • Store ID

Products has columns for:

  • Product name
  • Product cost
  • Product ID
  • Store ID

In Rails, I have two models – Store and Product – connected with a has_and_belongs_to_many relationship. The models have attributes matching each of the columns in the spreadsheets.

I’m looking to create a rake task that takes the spreadsheets as CSV files and creates linked rows in the Stores and Products databases, but being a coding newbie I’m finding it difficult. Adding data to one table from a .csv seems easy enough, but how can I use the matching “Product ID” column to link the data in the two csv files?

  • 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-29T20:15:31+00:00Added an answer on May 29, 2026 at 8:15 pm

    In general I would do something like the following:

    1. Start by creating the stores first as they are independent. As you create the store and save the object, add the store object to a hash of {storeid:}
    2. Then read in the products.csv (I’m assuming that there will be more than one product per store?).
    3. For each row in the product csv, create the product object and then set the association by looking up the store object from your hash with the id in the row you are reading, finally save your product object.

      class Store < ActiveRecord::Base  
      
      end
      
      
      class Product < ActiveRecord::Base  
      
        has_and_belongs_to_many :stores  
      
      end
      

    For rails I would guess that there is a quick way to do this via one of the many tools (rake etc).

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

Sidebar

Related Questions

Let's say I have a spreadsheet that has two columns of data. For example:
I have two excel spreadsheets, one contains data on various persons, while the other
Why drawing a map from google docs takes +50seconds, I have just two columns
I have data from two spreadsheets where I need to compare the quantities of
I have a Excel spreadsheet that has two tabs, I have data on the
I have two columns in a spreadsheet called A1 and A2. The data entered
I have two spreadsheets, one is a backup from an ecommerce store which contains
I have two spreadsheets... when one gets modified in a certain way I want
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I have an excel spreadsheet with two columns, one with a list of exercises

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.