ERROR_SILENT in DataWriter not functioning as expected?

Jaxel

Well-known member
Code:
$dw = XenForo_DataWriter::create('EWRmedio_DataWriter_Keywords', XenForo_DataWriter::ERROR_SILENT);
$dw->set('keyword_text', $text);
$dw->save();

"keyword_text" is defined as a UNIQUE column... I am trying to write to the table, but I want it to silently fail when it can't write to keyword_text because its not unique. I figured adding ERROR_SILENT would make the datawriter fail silently, like it did in vBulletin. However, it doesn't.

Mysqli statement execute error : Duplicate entry 'soulcaliburiv' for key 'keyword_text'
 
It just prevents validation errors, not DB errors. Ideally, you should be doing unique checks via validation.
 
I was hoping for a full silent failure option... if a video has 30 keywords, thats 30 additional queries for validation that I was hoping to avoid.
 
It just prevents validation errors, not DB errors. Ideally, you should be doing unique checks via validation.
Okay... if I can't fail silently... how would I check for unique COMPOSITE keys...

I have a table called EWRmedio_keylinks, which has a composite unique of (keyword_id, media_id), it also has a primary key of keylink_id. Basically, a keyword, can't be linked to the same media at the same time; very simple.
 
You can do the validation in _preSave. Have a look at the permission DW for an example.
 
You can do the validation in _preSave. Have a look at the permission DW for an example.
Why is it all my questions always have the SIMPLEST of solutions? Do I think too much?

Archimedes would have a field day...
 
Top Bottom