In my RESTful API I have a uniqueness validation for some database-column "X" within my ActiveRecord class and I'm using the activerecord-import gem for bulk-saving data. My app should reject requests in both of the following cases:
It seems like (1.) is working fine, but (2.) is not. Is this to be expected (maybe because the ActiveRecord uniqueness validation is performed "outside" the db), and if yes, is there simple way to handle this issue other than validating by hand before importing the new data?
The activerecord-import gem enforces validations by default, but perhaps handles uniqueness validation differently. If the database supports it, there is a on_duplicate_key_update which will update another column if it finds duplicate keys. More about this on the wiki. MySql supports it.
So you can either have a flag type column that is updated via on_duplicate_key_update whenever there are attempts to save duplicates. Or you have to do this one validation by hand
Edit The answer may not be correct, please refer to OP's comments for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With