beforeSave Problem

A place for users and developers of the Xataface to discuss and receive support.

beforeSave Problem

Postby 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'));
            }
        }
    }
dbaron2
 
Posts: 15
Joined: Wed Sep 30, 2009 10:27 pm

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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.
dbaron2
 
Posts: 15
Joined: Wed Sep 30, 2009 10:27 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 33 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved