Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
SingularAssociation#find_target uses unordered scoped.first #11774
Neither MySQL nor PostgreSQL guarantee order for queries without explicit order statement.
Existing code may result in has_one association getting multiple records on replace with newly created association (if scoped.first will return latter one, replace will not happen)
referenced this issue
Aug 17, 2013
pushed a commit
Aug 21, 2013
It would be fine if AR did not rely on ordered #first semantics. Singular association uses it to replace the old one. Unfortunately there is no clear way (AFAIK) to fix this for the singular association only.
I probably can buy backwards-compatibility reason for not merging ordered #first change, but it means that this particular issue is still a bug.
Thanks for reopening. I'll continue to look at solution (but still hope that somebody more fluent in AR can take a look).
The big problem are with multiple levels of responsibilities in inheritance chain, where we know what we need on the first step, but can apply order only on the last one
SingularAsociation#create_record (here we know what's going on) =>
SingularAssociation#find_target (here we can apply order)
I'm sorry but there is no case for breaking backward compatibility in a