diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 47c224d..4b6fbaf 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -171,8 +171,8 @@ public function __construct($databaseConnection = null, ?string $table = '', arr } /** - * magic function to make calls witch in function mapping stored in $operators and $sqlPart. - * also can call function of PDO object. + * Magic function to make calls to ActiveRecordData::OPERATORS or ActiveRecordData::SQL_PARTS. + * also can call function of databaseConnection object. * @param string $name function name * @param array $args The arguments of the function. * @return mixed Return the result of callback or the current object to make chain method calls. @@ -193,7 +193,9 @@ public function __call($name, $args) 'operator' => ActiveRecordData::SQL_PARTS[$name], 'target' => implode(', ', $args) ]); - } + } else if(method_exists($this->databaseConnection, $name) === true) { + return call_user_func_array([ $this->databaseConnection, $name ], $args); + } return $this; } diff --git a/tests/ActiveRecordPdoIntegrationTest.php b/tests/ActiveRecordPdoIntegrationTest.php index 805111d..8796778 100644 --- a/tests/ActiveRecordPdoIntegrationTest.php +++ b/tests/ActiveRecordPdoIntegrationTest.php @@ -4,6 +4,7 @@ use flight\ActiveRecord; use flight\database\pdo\PdoAdapter; +use flight\database\pdo\PdoStatementAdapter; use flight\tests\classes\Contact; use flight\tests\classes\User; use PDO; @@ -626,4 +627,11 @@ public function testTextBasedPrimaryKeyDuplicateKey() $this->expectExceptionMessage('UNIQUE constraint failed: my_text_table.my_pk'); $myTextTable2->save(); } + + public function testCallMethodPassingToPdoConnection() + { + $result = $this->ActiveRecord->prepare('SELECT * FROM user'); + $this->assertInstanceOf(PdoStatementAdapter::class, $result); + $this->assertNotInstanceOf(ActiveRecord::class, $result); + } }