Trigger depending on another trigger in different table

Archived from the Xataface Users forum.

meta — Wed May 21, 2008 8:56 am

Could I have a trigger in one tables delegate class depending on another trigger in another tables delegate class?

An example:

I have an afterSave trigger in the dc of the first table which automatically populates fields in the second table. This works well.

If I now have a beforeInsert trigger in the second tables dc it only works if I insert fields in the second table directly.

Can I make it so that this also works automatically? Kind of a chain-reaction.

Thank you

Markus


shannah — Wed May 21, 2008 11:14 am

The xataface triggers are called iff you use the xataface api for inserting the records.

e.g. In table1’s delegate class:

Code: Select all
`function afterInsert(&$record){
    // Insert a record into table2 so that table2’s triggers are NOT called
    $res = mysql_query(“insert into table2 ….”, df_db());

    // Insert a record into table2 so that table2’s triggers ARE called
    $rec2 = new Dataface_Record(‘table2’, array());
    $rec2->setValues( array(
        ‘col1’ => ‘val1’,
        ‘col2’ => ‘val2’,
        …
    ));
    $rec2->save();
}`

Hope this helps.

-Steve