Closed
Description
- Laravel-mongodb Version: 3.9.9
- PHP Version: 8.1.0
- Database Driver & Version:
Description:
Queries, populated with Spaties's query builder are not correct.
Spatie's package adds table prefix for WHERE filters: select * from table 'example' ... where 'example'.'column' = ?
MongoDB driver can not execute such queries, as it interprets this query as deep object comparison ({ "example": { "column": "value" } }
) instead of { "column": "value" }
Adding table (or collection) prefix to query is correct behavior and part of Model function: ``
Temporal fix is adding this to your model:
public function qualifyColumn($column)
{
return Str::after($column, $this->getTable() . '.');
}
Steps to reproduce
composer require spatie/query-builder
- Create MongoDB model
-
QueryBuilder::for(MongoModel::class) ->allowedFiilter([ AllowedFilter::exact('column'), ]) ->dd();
/some-route?filter[column]=value
Expected behaviour
{
"$and": {
"column": "value",
}
}
Actual behaviour
{
"$and": {
"mongo-model.column": "value",
}
}