I’m saving some objects on the DB that should be unique for a given
So I have added this to the model:
validates_uniqueness_of :related_date, :scope => [:indicator_id,
So an object with a given indicator_id and edone_id for a given related
date can only exist once in the DB
I have added an index to the table like this:
add_index :kpivalues, [:related_date, :indicator_id, :edone_id], :unique
Everything seems to go ok and if I try to create an object with the same
related date it fails.
BUT since I added that constraint the objects are created one day before
If the related_date is 2012-11-23 I can see form the logs that the check
for the existing value is actually looking for the 22nd
(DEBUG) 15489 Kpivalue Exists (0.4ms) SELECT 1 FROM “kpivalues” WHERE
(“kpivalues”.“related_date” = ‘2012-11-22 22:00:00.000000’ AND
“kpivalues”.“indicator_id” = 1485 AND “kpivalues”.“edone_id” IS NULL)
Any ideas why it is looking for the previous day?