Page 1 of 1

afterImport-trigger?

PostPosted: Thu Nov 27, 2008 10:42 am
by meta
Hi Steve, hi all,

is it possible to have an afterImport-trigger?

I try to do the following. After having imported a couple of records I would like to do an update on all the imported records.

The update should run automatically and insert a combination of the recently inserted auto_increment (v_id, my primary key) and another populated field of the table.

If I try it with an afterInsert function it gives me an error because the auto_incremet is not actually there I suppose.

Code: Select all
   function afterInsert($record) {
   $app =& Dataface_Application::getInstance();
   $record =& $app->getRecord();
   $vid = $record->val('v_id');
   $B3IDresult = $record->val('B3_ID_result');
   $sql = mysql_query("UPDATE versuch SET v_b3_ID='$B3IDresult | $vid' WHERE v_id = $vid");
   }


gives back: Fatal error: Call to a member function val() on a non-object in C:\xampp\htdocs\webseiten\biogasdb.lokal\tables\versuch\versuch.php on line 47 where line 47 is: $vid = $record->val('v_id');
which means that the auto_increment v_id is not in place.

When I try an afterSave trigger it will work on every single record after saving. This would probably be a possibility but you have to save every single of the imported records manually (could be many).

Any Idea?

Thank you
Markus

PostPosted: Fri Nov 28, 2008 10:55 am
by shannah
Ditch the call to $app->getRecord()

It is overwriting the $record with a null record. This should give you the result that you want.

-Steve

PostPosted: Fri Nov 28, 2008 11:38 am
by meta
You are right ;-) Thank you for that, too.

Markus