Call to a member function prepare() on null new Builder #3109
-
Using laravel bouncer I got some error from this code. I already extended all use DocumentModel, it works when populating all roles and abilities, but when assigning a user to a role I got an error from this method public static function query($table)
{
$query = new Builder(
$connection = static::user()->getConnection(),
$connection->getQueryGrammar(),
$connection->getPostProcessor()
);
return $query->from(static::table($table));
} |
Beta Was this translation helpful? Give feedback.
Answered by
GromNaN
Aug 21, 2024
Replies: 2 comments 1 reply
-
Call to a member function prepare() on null
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
403▕ // For select statements, we'll simply execute the query and return an array
404▕ // of the database result set. Each element in the array will be a single
405▕ // row from the database table, and will either be an array or objects.
406▕ $statement = $this->prepared(
➜ 407▕ $this->getPdoForSelect($useReadPdo)->prepare($query)
408▕ );
409▕
410▕ $this->bindValues($statement, $this->prepareBindings($bindings));
411▕
1 vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
2 vendor/laravel/framework/src/Illuminate/Database/Connection.php:812
3 vendor/laravel/framework/src/Illuminate/Database/Connection.php:779
4 vendor/laravel/framework/src/Illuminate/Database/Connection.php:398
5 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3088
6 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3073
7 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3661
8 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3072
9 vendor/silber/bouncer/src/Conductors/AssignsRoles.php:85
10 vendor/silber/bouncer/src/Conductors/AssignsRoles.php:63
11 vendor/silber/bouncer/src/Conductors/AssignsRoles.php:41
12 vendor/silber/bouncer/src/Database/Concerns/HasRoles.php:65
13 tests/Feature/Tenant/Auth/AuthenticationTest.php:14 I extracted some parts that may help track the issue protected function getExistingAttachRecords($roleIds, $morphType, $authorityIds)
{
$query = $this->newPivotTableQuery()
->whereIn('role_id', $roleIds->all())
->whereIn('entity_id', $authorityIds->all())
->where('entity_type', $morphType);
Models::scope()->applyToRelationQuery($query, $query->from);
return new Collection($query->get());
}
protected function newPivotTableQuery()
{
return Models::query('assigned_roles');
}
public static function query($table)
{
$query = new Builder(
$connection = static::user()->getConnection(),
$connection->getQueryGrammar(),
$connection->getPostProcessor()
);
return $query->from(static::table($table));
}
|
Beta Was this translation helpful? Give feedback.
1 reply
-
After checking it, bouncer could not be supported now, it uses whereColumn and other unsupported builder when running its test |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that the package is incompatible with MongoDB. We don't use "pivot table" for many-to-many relationships as MongoDB document can contain the list of reference ids. The logic of querying the pivot table is incompatible here because they don't build the query using Eloquent relation system; probably for performance reason.