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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:37:31+00:00 2026-06-13T17:37:31+00:00

According to the present Rails documentation, regarding the << operator on a has_many relationship

  • 0

According to the present Rails documentation, regarding the << operator on a has_many relationship on an existing object:

collection<<(object, …)

Adds one or more objects to the collection by setting their foreign keys
to the collection’s primary key. 

(This is the interesting bit)

Note that this operation instantly fires update sql without waiting for 
the save or update call on the parent object.

I didn’t realize this would happen, I was quite surprised; I could have sworn this was not the case in the past, though I admit I could be wrong.

In either case, I haven’t been able to find any additional documentation regarding this, however I wonder if there is a way to prevent this update?

My situation is simple, I merely have an object which exists in the database, which is being prepared for an “edit” page. I append one or multiple related objects before the page is render. C’est tout.

Update:
Apparently the same update-scenario also occurs if you set the has_many relationship directly from an array using the = operator.

  • 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-06-13T17:37:33+00:00Added an answer on June 13, 2026 at 5:37 pm

    Use the collection’s build method. That won’t immediately fire a SQL statement like the others do.

    foo.bars.build(attributes)
    foo.save
    

    Lots of good information can be found here: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

    Note: This method assumes you have the flexibility to create your objects through the build method rather than using Bar.new.

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

Sidebar

Related Questions

According to the documentation here: https://github.com/playframework/Play20/wiki/AssetsGoogleClosureCompiler it says: Any JavaScript file present in app/assets
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
According to Hibernate documentation : After observing that arrays cannot be lazy , you
According to Microsoft, the SharePoint help pages present a security concern and should be
According to this reference for operator new : Global dynamic storage operator functions are
I'd like to use the Composite pattern for forwarding calls received by one object
http://processing.org/learning/eclipse/ according step 5, I used PApplet.main( new String[] { --present, MyGame }); in
According to the ECMA-262 a native object object in an ECMAScript implementation whose semantics
In the given case a User may: invite many invitees (has_many :invitations) accept one
According to this tutorial , the DatePicker control is definitely present in the Javascript

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.