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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:20:32+00:00 2026-05-23T17:20:32+00:00

Basically, what I’m trying to do is to seed my database with a bunch

  • 0

Basically, what I’m trying to do is to seed my database with a bunch of initial data for my web app. For example, there are a list of products that all have one product_type.

My seeds.rb has the following code:

ProductType.delete_all
ProductType.create(:name => 'Furniture')

Product.delete_all
Product.create(:name => 'Chair', :type_id => ProductType.first.id, :packaging => '2 for $20', :price_per => 0.1, :default_packaging_number => 2)

Now, my issue is that the ProductType.first.id is merely a placeholder. What I would really like to do is to put something like:

:type_id => ProductType.where(:name => "Furniture").id

The issue is that when I do this, I get returned a huge number (70247318042560) that is clearly not the id. The console also returns the warning

warning Object#id will be deprecated; use Object#object_id

When I use the .object_id at the end of the where statement, it still returns that same large and incorrect number.

How do I pull the id of the furniture ProductType from the database? Do I need to modify permissions or something to access 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-23T17:20:32+00:00Added an answer on May 23, 2026 at 5:20 pm

    First:

    When you call ProductType.where() you’re getting an ActiveRecord Relation, which is basically an array of results, even if there’s only one record in that result set.

    Try calling ProductType.where(...whatever...).first.id and see if that solves your problem.

    Second, a better way:

    Just save the product to a local variable.

    ProductType.delete_all
    furniture = ProductType.create(:name => 'Furniture')
    
    Product.delete_all
    Product.create(:name => 'Chair', :type => furniture, :packaging => '2 for $20', :price_per => 0.1, :default_packaging_number => 2)
    

    Make sure you use the right association name (I’m guessing type…).

    NOTE ActiveRecord already makes use of the “Type” column for polymorphic and single-table-inheritance relationships. If you’re association is setup where your relationship between Products and ProductTypes is called “Type” then you may be creating a conflict, or you may risk a conflict in the future. It’s best to not use that as a column name.

    Why not stick with the default? If Product belongs_to ProductType then the default column name would be product_type_id

    A final alternative:

    If you reset your DB when you seed (probably a good idea) then you don’t need to call Product.delete_all, the db will already be empty.

    In that case you can just do ProductType.find(1) — if you’ve just started creating records the ids will be 1, 2, 3 etc in the order you create them.

    Hope this helps, feel free to ask questions!

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

Sidebar

Related Questions

Basically from a database I am getting data that is formatted like this nameofproject101
Basically I am trying to restart a service from a php web page. Here
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically, what I'm trying to create is a page of div tags, each has
Basically what I am doing is giving a user a list of terms via
Basically there is a file called 8puzzle.py and I want to import the file
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically I have an iframe loaded that is accessed from the parent whenever it

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.