Closed varvaray closed 3 years ago
I wrote a workaround -
def uniqueness
errors.add(:base, :already_used) if Multiplier.exists?(code: code, partnerid: brand_id)
end
with validate :uniqueness for the model, which seems to work, but would be nice to have uniqueness support out of the box.
Thanks for the report - that does seem like a bug.
Took a look at this at it works as expected on the latest version (CPK 12.) on Rails 6.0..
So going to close this. CPK 8.* is no longer supported, I'd recommend upgrading if at all possible.
Gem version - composite_primary_keys (8.1.3) Rails version - rails (4.2.11)
I have a model with composite primary key -
self.primary_key = %i(code partnerid)
And i have a uniqueness validation on code looking like that -It works nicely on create -
But on update the exists request to database looks like that -
Which results in passing it through and then getting ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry 'LOL-0' for key 'PRIMARY': UPDATE