Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
636 stars 200 forks source link

Call to a member function lastInsertId() on null #304

Closed asifnadaf closed 4 years ago

asifnadaf commented 6 years ago

Hi,

I using Laravel 5.6 and NeoEloquent 1.4.7. I am getting following error while creating a record for new record on neo4j. However, the node gets created on Neo4j.

/var/www/html/plusconnect.tk/public_html/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php

/**
 * Process an  "insert get ID" query.
 *
 * @param  \Illuminate\Database\Query\Builder $query
 * @param  string $sql
 * @param  array $values
 * @param  string $sequence
 * @return int
 */
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
    $query->getConnection()->insert($sql, $values);

    if ($sequence != null) {
        $id = $query->getConnection()->getPdo()->lastInsertId($sequence);
    } else {
        $id = null;
    }

    return is_numeric($id) ? (int)$id : $id;
}

Arguments "Call to a member function lastInsertId() on null"

The error goes away if the line below is commented from vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php $id = $query->getConnection()->getPdo()->lastInsertId($sequence);

I am using the above solution as a workaround. What could be the issue?

May be it is expecting the primary key of the last record created and NeoEloquent is not receiving it.

Thanks

smrsln commented 6 years ago

Hi, Probably you are using Eloquent class of Laravel for querying database. If you have problem with your model about showing the Neoeloquent class try this:

class User extends \NeoEloquent{}

I hope it will solve your problem.

asifnadaf commented 6 years ago

Thanks I will try this solution and revert.

stale[bot] commented 4 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.