Closed tdumalin closed 3 years ago
Do you have a minimal repository where I can debug this ? @tdumalin
Hi @VincentLanglet ,
unfortunately no, i can manage to create one when i have some free time
@VincentLanglet, I think this issue may be related to #5589.
Indeed @phansys, Time to try again https://github.com/sonata-project/SonataAdminBundle/pull/5589#issuecomment-504707598
@VincentLanglet I guess it means I don't need to create a micro repository ?
@VincentLanglet I guess it means I don't need to create a micro repository ?
I don't think it will be needed. But I also prefer to warn use, this bug is not easy to fix and exists for a long time...
@VincentLanglet I guess it means I don't need to create a micro repository ?
I don't think it will be needed. But I also prefer to warn use, this bug is not easy to fix and exists for a long time...
Ok no problem, for now i use the callback feature when i need to filter on multiple fields, thanks for the help
Changing the Datagrid::applyFilters
method could be a solution
$originalWhereClause = $this->query->getWhereClause();
$this->query->resetWhereClause();
foreach ($this->getFilters() as $name => $filter) {
$this->values[$name] = isset($this->values[$name]) ? $this->values[$name] : null;
$filterFormName = $filter->getFormName();
$value = $this->values[$filterFormName]['value'] ?? '';
$type = $this->values[$filterFormName]['type'] ?? '';
if ('' !== $value || '' !== $type) {
$filter->apply($this->query, $data[$filterFormName]);
}
}
$filterWhereClause = $this->query->getWhereClause();
$this->query->resetWhereClause();
$this->query->applyWhereClause($originalWhereClause);
$this->query->applyWhereClause($filterWhereClause);
Could be a solution.
@franmomu does a getWhereClause
, resetWhereClause
and applyWhereClause
can make sens for MongoDB ?
🤔 mmm I think there is no API in doctrine/mongodb-odm
to perform those operations and there is no concept of where
.
🤔 mmm I think there is no API in
doctrine/mongodb-odm
to perform those operations and there is no concept ofwhere
.
In ORM, the issue is that if you use
->andWhere("$alias.lastname = Foo")
In the create query and you have two filters
If the filter are used with the AND condition, there is no issue, the request will be
->andWhere("$alias.lastname = Foo")
->andWhere("$alias.firstname = Bar")
->andWhere("$alias.birthdate = 21/01/1991")
Lastname = Foo AND Firstname = Bar AND Birthdate = 21/01/1991
But with the OR condition, it's
->andWhere("$alias.lastname = Foo")
->orWhere("$alias.firstname = Bar")
->orWhere("$alias.birthdate = 21/01/1991")
Lastname = Foo OR Firstname = Bar OR Birthdate = 21/01/1991
Instead of
Lastname = Foo AND [ Firstname = Bar OR Birthdate = 21/01/1991 ]
If there is no concept of where
, how would you solve this in MondoDB persistence bundle ?
@tdumalin Do you still have the issue with the latest version ?
@phansys made some improvement with the OR filter
Environment
Sonata packages
Symfony packages
PHP version
Subject
ModelAutocompleteFilter doesn't work correctly with multiple properties and custom createQuery
Steps to reproduce
let's imagine a marketplace with stores who sell products, a product is linked to a store and it can have many variants. When a user log in, we store the id of it's store in session in 'store_id' key. After word he can only see's products and variants from the store setted in session Here's some sample of the entities and related admins
Expected results
Actual results