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

  • Home
  • SEARCH
  • 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 6096331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:54:54+00:00 2026-05-23T12:54:54+00:00

I have a item tracking system which has an Item model which has a

  • 0

I have a item tracking system which has an Item model which has a one to many relationship with an Invoice. Meaning that one invoice can have many items and an item can belong to one invoice.

I’ve now run into the need to return an Item into stock which for my system means setting the delivered boolean field back to false, but unless I set invoice_id to nil it will still show up as awaiting delivery to a customer and if I do nil it then my system will have no record of ever invoicing a customer for that item.

The only way I can see of this working well is to have a previous_invoices field that stores the ids of invoices its been on. Doing this would work from an Items point of view Item.previous_invoices would make sense but it would not show up in Invoice.items and to get the items which have been returned I would need to do a db search with a LIKE condition.

I’d rather not use a many to many association as it will only be the tiny fraction of items that are returned which need to use the table.

Is there anyway of doing this in rails or with a gem which can handle the finds on either side?

  • 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-23T12:54:55+00:00Added an answer on May 23, 2026 at 12:54 pm

    The relationship between Invoice and Item is many-to-many, and you’re just causing yourself difficulty by avoiding implementing it as such. The cleanest solution is an InvoiceItems table with something like a ‘returned’ field that you would check when you pull invoice items, perhaps with a conditional on the invoice’s HABTM association with items.

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

Sidebar

Related Questions

In my edit action, I have @item = current_user.shop.items.find(params[:id]) So that the user can
TFS (2008) has the great feature of work item tracking where I can easily
Imagine I have a table called item that has a column called price. In
I have a Controller/View for a generic list of items, that can be extended
I have an Item class and a Comment class. Items have many embedded comments.
I have a treeview (winforms) which have different item types on it. I have
I have a ListBox that when in focus, and when I have an item
I have a trouble trying to get this working. I have an Item model,
I have a 'complex item' that is in XML, Then a 'workitem' (in xml)
I have been asked to keep track of how many times each item comes

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.