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

The Archive Base Latest Questions

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

There are two models. One is rfq and another one is standard. It is

  • 0

There are two models. One is rfq and another one is standard. It is like:

class Rfq << ActiveRecord::Base
  has_and_belongs_to_many :standards
end

class Standard << ActiveRecord::Base
  has_and_belongs_to_many :rfqs
end

Table rfqs_standards has been created. My question is when creating rfq, how to save the paid of rfq_id and standard_id in table rfqs_standards automatically.

Thought adding accepts_nested_attributes_for :standard in rfq model. However since there is no real attributes (but just pair of id) saved for this many-to-many relationship, this seems not the right way.

Both rfq and standard was declared in routes.rb as resources :rfqs and resources :standards.

The procedure is when creating rfq, standard will be picked up via a drop down list. Then rfq is saved and at the same time, a new entry in joint table is created. When creating new standard, there is no need to create entry in joint table.

Any suggestion to save the id in joint table? Thanks.

  • 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-27T22:32:14+00:00Added an answer on May 27, 2026 at 10:32 pm

    this is easier than you might think because it’s handled automatically by ActiveRecord.

    When you say “has_and_belongs_to_many”, you’re telling AR to associate those two models with a many-to-many relationship using the table, and for the most part you no longer need to worry about the join table. When you add an instance of Standard to an Rfq’s list of standards, this will be done for you.

    Here’s an example:

    rfq = Rfq.create
    standard = Standard.create
    rfq.standards << standard
    

    We’ve created each of the objects, and the third line creates the connection, saving a new record in the rfqs_standards table with the proper ids. rqf.standards looks and acts like a normal array, but when you assign objects to it, ActiveRecord does the database work for you.

    After creating the records, you could have also done:

    standard.rfqs << rfq
    

    You could also do both at the same time:

    rfq = Rfq.create
    standard rfq.standards.create
    

    This created an rfq, then created a standard that is automatically connected to the rfq. You can do the same thing in reverse:

    standard = Standard.create
    rfq = standard.rfqs.create
    

    I hope this helps!

    UPDATE: Since you mentioned forms and automatic saving, read my article on nested attributes that shows how to implement that, including full code samples.

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

Sidebar

Related Questions

I'm working on an association between two models: class Person < ActiveRecord::Base belongs_to :user
I have the following two models: class Message < ActiveRecord::Base belongs_to :to_user, :class_name =>
I have two models ForumThread and Post set-up like this: class ForumThread < ActiveRecord::Cached
There are two databases in SQL Server 2005: One called A and another one
I have two models Category and Entry . There is another model ExtEntry that
I have two models in Django like follows(in pseudo code) class Medicine(db.Model): field_1 =
I've just created two models and one join table. Person, Adress (create_adresses_personss) class Person
Having a rfq model in the app. There are two fields. One is need_report
Is there a widget in Django 1.0.2 to render a models.BooleanField as two radio
In my current project, I have two models, Version and Comment. There is a

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.