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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:46:13+00:00 2026-06-05T15:46:13+00:00

I have a list_users model with fields (id, list_id, user_id) which joins Users w

  • 0

I have a list_users model with fields (id, list_id, user_id) which joins Users w Lists.

In my rails model for Lists I have the following validation to prevent duplicates.

  validates_uniqueness_of :user_id, :scope => :list_id

However every now and then a duplicate record is being created in the list_users table in the DB which ends up breaking a lot of things…

=> [#<ListMember id: 37199, user_id: 1203713, list_id: 13651, created_at: "2012-06-04 20:02:11", updated_at: "2012-06-04 20:02:11">

=> [#<ListMember id: 37195, user_id: 1203713, list_id: 13651, created_at: "2012-06-04 20:01:40", updated_at: "2012-06-04 20:01:40">

Has anyone seen this before? 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-06-05T15:46:15+00:00Added an answer on June 5, 2026 at 3:46 pm

    I have seen this before. I don’t know if the context is the same for you, but the reason I was seeing this is basically that I was accidentally building two records with the same id pair in memory, running the validations on the two of them, and THEN saving both to the DB. The uniqueness validation didn’t catch this because neither record existed in the DB at the point the validation was run. Maybe this is what you’re experiencing.

    EDIT: Seeing as how close together in time your records were created, I’d say this is likely the case.

    Also, you should migrate an index to the db withadd_index :list_users, [:user_id, :list_id]

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

Sidebar

Related Questions

I have a model Token with three fields user_id,product_id and unique_token .In the controller
User is a model. I have 100 users. I need to present the list
I have a list: Collection users which has around 100K+ records of users (all
I have a list of online users, which I refresh every 30 seconds with
I have a script which loops through a list of users (samaccountname): # Read
I have two entities, projects and users. These are modeled in Rails using Mongoid
I have the following models: class UserProfile(models.Model): user = models.OneToOneField(User) score = models.PositiveIntegerField() class
I have the following very simple Ext JS 4 script which is supposed to
So I have a view model call ProductViewModel which has a list of sites
I have a rails app which currently has 3 models: Post , User and

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.