beforeSave Problem
Archived from the Xataface Users forum.
dbaron2 — Mon Dec 14, 2009 12:37 pm
Hello,
I am using a delegate class to set the value of 3 fields in my record before the record is saved. The code reads the previous values for these 3 fields and sets them back to their prior values under certain cirumstances.
The problem is that the code always gets the wrong DB record. It gets the first record every time which is not the correct one. What am I doing wrong?
- Code: Select all
function beforeSave(&$record){ $db_rec = df_get_record('change_memos', array('change_memo_id'=>$record->val('change_memo_id'))); if ($db_rec){ $record->setValue('last_steps', $db_rec->val('last_steps')); $record->setValue('last_reminded', $db_rec->val('last_reminded')); if ($record->val('workflow_id') == ""){ $record->setValue('workflow_id', $db_rec->val('workflow_id')); } } }
shannah — Mon Dec 14, 2009 1:41 pm
Change
- Code: Select all
$db_rec = df_get_record('change_memos', array('change_memo_id'=>$record->val('change_memo_id')));
to
- Code: Select all
$db_rec = df_get_record('change_memos', array('change_memo_id'=>'='.$record->val('change_memo_id')));
In the first case, if change_memo_id is null or blank, then your query will match any record from the change_memos table. In the second case, if change_memo_id is blank or null, it will only match records where change_memo_id is blank or null.
-Steve
dbaron2 — Mon Dec 14, 2009 8:14 pm
Thanks again! That did the trick.
I noticed that small syntax difference in another posting, but I didn’t understand the significance of it.