Search code examples
phpmysqlormtriggersredbean

Does redbean php consider created mysql-triggers?


I am using redbeanphp 4.3 and struggling to understand why a mysql-db-trigger does not get triggered (or may be ignored).

When I work directly in the database (with phpmyadmin) and insert a row in table B, a column in table A gets updated. When I work indrectly with the database (via a rest-api and therefore with redbean php), the row is inserted as well in table B, but the column in table A does not get updated.

This exact same behaviour I found in my android application with sugarorm too.

I then reasoned, that using an ORM ignores the usage of triggers. But so far I did not find any statement support my thesis, not in some forums, the redbean documentation nor in the rd.php source code.

An explanation or any help would be appreciated. Thanks in advance.

Edit 1: A script using mysqli and pdo-driver does result in the same behaviour as manual insertion (the column gets updated). Therefore PDO can not be the reason.

Solution:

Table A and B have an 1:N relation.

The problem was a misuse of redbean's R::store() method. The object1 of table A was loaded, an object2 of table B was inserted (by R::store()), the trigger was executed, but the object1 of table A did not recognize it. A final R::store() on object1 has overwritten the background updates to the initial state.

So the solution is quite simple: removing R::store() on objects of table B. When R::store() is called on object1 of table A, it first updates entity A and inserts entity B afterwards, which will trigger the update of object1.


Solution

  • Try to debug the sql querys created by redBean and check if there is a column update or something else after your insert.

    1. Configure redBean to log sql querys:

      R::debug( TRUE, 3 );

    2. Access and print the log:

      $logs = R::getDatabaseAdapter()->getDatabase()->getLogger()->getLogs(); print_r( $logs );

    You will find more information about debugging redBean on their official site.