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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:07:20+00:00 2026-05-25T18:07:20+00:00

I have a Rails application, with two models: SalesTransactions and PurchaseOrders. In the PurchaseOrders

  • 0

I have a Rails application, with two models: SalesTransactions and PurchaseOrders.

In the PurchaseOrders model, new entries are registered using ‘purchase_order_number’ as the key field. I use the create method of the model to search if that ‘purchase_order_number’ has been previously registered, and if so, reuse that record and use its id in the SalesTransaction record. If that name wasn’t already registered, I go ahead and perform the create, and then use the new PurchaseOrder record id in the SalesTransaction (the foreign_id linking to the associated PO).

Note that I don’t have the existing PurchaseOrder record id until I’ve done a look-up in the create method (so this is not a question of ‘how do I update a record using ‘accepts_nested_attributes_for’?’, I can do that once I have the id).

In some situations, my application records a new SalesTransaction, and creates a new PurchaseOrder at the same time. It uses accepts_nested_attributes_for to create the PurchaseOrder record.

The problem appears to be that when using ‘accepts_nested_attributes_for’, create is not called and so my model does not have the opportunity to intercept the create, and look-up if the ‘purchase_order_number’ has already been registered and handle that case.

I’d appreciate suggestions as to how to intercept ‘accepts_nested_attributes_for’ creations to allow some pre-processing (i.e. look up if the PurchaseOrder record with that number already exists, and if so, use it).

Not all Sales have a PurchaseOrder, so the PurchaseOrder record is optional within a SalesTransaction.

(I’ve seen a kludge involving :reject_if, but that does not allow me to add the existing record id as the foreign_id within the parent record.)

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-25T18:07:21+00:00Added an answer on May 25, 2026 at 6:07 pm

    OK, I’ve left this question out there for a while, and offered a bounty, but I’ve not got the answer I’m looking for (though I certainly appreciate folk trying to help).

    I’m concluding that I wasn’t missing some trick and, at the time of writing, there isn’t a neat solution, only work-arounds.

    As such, I’m going to rewrite my App to avoid using accept_nested_attributes_for, and post the SalesTransaction and the PurchaseOrder records separately, so the create code can be applied in both cases.

    A shame, as accept_nested… is pretty cool otherwise, but it’s not complete enough in this case.

    I still love Rails 😉

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

Sidebar

Related Questions

I have a Rails simple application that has two main models. A person model
In rails application I have two models: Food and Drink . Both food and
In my rails application I have two models called Kases and Notes. They work
I have two models/tables in my Rails application: discussions and comments. Each discussion has_many
My rails application has two models, gallery and photo. Galleries have many photos and
In my Rails application, I have two models, Articles and Projects, which are both
I am developing a rails application in which I have two models User and
I have a Rails 3.1.1 application with the following models: Company Member The two
I have had this problem w/ two seperate WYSWYG editors in my rails application
I'm working on a Rails application where I have some a set of two

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.