dimitriBouteille / wp-orm

WordPress ORM with Eloquent, an object-relational mapper that makes it enjoyable to interact with your database.
https://packagist.org/packages/dbout/wp-orm
MIT License
59 stars 4 forks source link

[BUG]: "This database engine does not support upserts" but MySQL supports it #66

Closed rafaucau closed 4 months ago

rafaucau commented 4 months ago

Describe the bug

When I try to use the upsert method, I get this error:

Fatal error: Uncaught RuntimeException: This database engine does not support upserts. in /var/www/vhosts/localhost/vendor/illuminate/database/Query/Grammars/Grammar.php:1206 Stack trace: #0 /var/www/vhosts/localhost/vendor/illuminate/database/Query/Builder.php(3646): Illuminate\Database\Query\Grammars\Grammar->compileUpsert() #1 /var/www/vhosts/localhost/vendor/illuminate/database/Eloquent/Builder.php(1086): Illuminate\Database\Query\Builder->upsert() #2 /var/www/vhosts/localhost/vendor/illuminate/support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder->upsert() #3 /var/www/vhosts/localhost/vendor/illuminate/database/Eloquent/Model.php(2334): Illuminate\Database\Eloquent\Model->forwardCallTo() #4 /var/www/vhosts/localhost/vendor/dbout/wp-orm/src/Orm/AbstractModel.php(85): Illuminate\Database\Eloquent\Model->__call() #5 /var/www/vhosts/localhost/vendor/illuminate/database/Eloquent/Model.php(2346): Dbout\WpOrm\Orm\AbstractModel->__call() #6 /var/www/vhosts/localhost/packages/plugins/****/includes/Admin.php(31): Illuminate\Database\Eloquent\Model::__callStatic() #7 /var/www/vhosts/localhost/html/wp/wp-includes/class-wp-hook.php(324): ****\Admin->***\{closure}() #8 /var/www/vhosts/localhost/html/wp/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #9 /var/www/vhosts/localhost/html/wp/wp-includes/plugin.php(517): WP_Hook->do_action() #10 /var/www/vhosts/localhost/html/wp/wp-admin/admin.php(259): do_action() #11 /var/www/vhosts/localhost/html/wp/wp-admin/edit.php(10): require_once('...') #12 {main} thrown in /var/www/vhosts/localhost/vendor/illuminate/database/Query/Grammars/Grammar.php on line 1206

Steps to reproduce the issue

  1. Create Model
  2. Try to use upsert method on it, for example:
    TestStat::upsert(
    [[
        'test_id' => $test_id,
        'count' => 1,
    ]],
    [ 'test_id' ],
    [ 'count' => Database::getInstance()->raw( 'count + 1' ) ]
    );

Expected behavior

The upsert method should work, as MySQL / MariaDB supports it.

Your setup

Additional context

This is implemented in MySqlGrammar: https://github.com/illuminate/database/blob/c57f5c8d3e55d9c952a2ad5f432bcb1dc2d3322c/Query/Grammars/MySqlGrammar.php#L246-L269

But not in Grammar: https://github.com/illuminate/database/blob/5a121a1507ea69dfd416a618415dada9dd4a50b4/Query/Grammars/Grammar.php#L1306

dimitriBouteille commented 4 months ago

Hello again @rafaucau

Thanks for opening this issue. I look to fix this bug as quickly as possible, you will be informed when it is done.

Best,

dimitriBouteille commented 4 months ago

Hi @rafaucau

The bug has been fixed in v3.2.0 :rocket: