Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 197 forks source link

Model::create() and Model::on('neo4j')->create() still use the default connection #285

Closed ideepblue closed 3 years ago

ideepblue commented 6 years ago

In my application, I use MySQL and Neo4j at the same time. So I manually assign the neo4j connection for the Model which uses Neo4j. For example:

use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquentModel;
use Vinelab\NeoEloquent\Eloquent\SoftDeletes;

class SomeModel extends NeoEloquentModel
{
    use SoftDeletes;

    protected $connection = 'neo4j';

    /**
     * @var array Soft deleting column
     */
    protected $dates = ['deleted_at'];
}

I followed the instruction to save Neo4j Model, which works:

$someModel = new SomeModel(['name' => 'some name']);
$someModel->save();

However, I tried the other two ways, which doesn't work. I debugged the code and found they always use the default database connection setting mysql.

$someModel = SomeModel::create(['name' => 'some name']);
$someModel = SomeModel::on('neo4j')->create(['name' => 'some name']);
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.