New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Association builder creates duplicates when associated table is :id => false #9201
Comments
I have tested and confirmed the same failure as of 2f0c26b |
Sorry for comment spam. Workaround: class B < ActiveRecord::Base
def id
# the natural key
end
end |
What's the "natural key" in your credit card example, the |
@carlosantoniodasilva I think you're right, I could have a primary key in my example because two customers will never have the same However, it was just an example. Perhaps I should come up with a better example. I do think the current behavior is wrong regardless of my example. |
I investigates a bit and on master the problem seems to be fixed. I attached a test-case which passes on master and fails on @carlosantoniodasilva I'd like to find the commit that fixed the problem to determine if we want to include my test-case but I'm not sure how to find it. What do you suggest? |
I think it's good to have a test case that ensures it is fixed and won't break again in master. Unfortunately I don't have any idea other than running the bundle on every bisect, which is quite painful to do. But if it cannot be backported, that's fine because at least it's fixed in master and people migrating to rails 4 will have it fixed. |
If model A has_many B, and B uses a natural key instead of an "id" column, creating a B through A's B-association builder results in A's B-association array containing two duplicate copies.
Steps to reproduce:
Expected results:
A's B-association array contains exactly the newly created B
Actual results:
A's B-association array contains two identical copies of the newly created B
Note:
"reloading" the A instance removes the duplicate copy.
This bug occurs with ActiveRecord 3.2.11.
I have reproduced the behavior using both PostgreSQL and SQLite.
For a full test case, see https://github.com/samwgoldman/ar_natural_key_bug
The text was updated successfully, but these errors were encountered: