shannah wrote:If date won't do what you want, then there are still many solutions. If you can't do any PHP coding you will be limited as to your solutions. One example solution would be to create a column that stores a hash that would be unique on the text and date. Then you could calculate this hash in the beforeSave() method. E.g.
1. Add a column named 'hash' to your table . Varchar(32). This will be used to store an md5 hash that is calculated using the date and text fields.
2. Add a unique key on this 'hash' column so that no two rows can contain the same hash.
3. Calculate the hash in the beforeSave() method of the table delegate class:
- Code: Select all
function beforeSave(&$record){
$hash = md5(md5($record->strval('textfield')).md5($record->strval('datefield')));
$record->setValue('hash', $hash);
}
Thx shannah for the quick answer. If I understand you right is this the same result than the code with TINYTEXT and DATE:
CREATE UNIQUE INDEX `index_pdv` (`textfield`(10), `datefield`)
text_field: TINYTEXT(first 10 letters) all works fine
datefield: DATE(wrong date(6h 30min different???) but good format for daily unique)
DATETIME(wrong for daily unique but right date inside. can not chose the first 6 letters because of error 1089)
TIMESTAMP(wrong for daily unique but right date inside. can not chose the first 6 letters because of error 1089)
If I am not wrong I will get with your code also the wrong date(exactly from 5:30pm). So it will me bring me a wrong result from 5:30pm to midnight.
When i will use TIMESTAMP or DATETIME I can´t get the unique from the day because I can not chose only the date(exclude the time).
I don´t understand why I get a different time(date) with DATE and DATETIME.