-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
Description
I've just done some tests to filter list results with objects related in many to many relations.
I've tried to fix this issue for Propel, but that's not finished so I'm just putting here some works to remind me later and to have feedbacks.
Fix config type:
filter_types:
propel:
collection: model
Fix PropelQueryFilter:
public function addCollectionFilter($field, $value)
{
list($query, $filteredField) = $this->addTablePathToField($field);
if ($value instanceof \PropelObjectCollection) {
$value = $value->toArray();
}
if (!is_array($value)) {
$value = array($value->getId());
}
if (strstr($field, '.')) {
list($table, $field) = explode('.', $field);
} else {
$table = $field;
$field = 'Id';
}
$query = call_user_func_array(array($query, 'use'.$table.'Query'), array());
$query->filterBy($field, $value, \Criteria::IN)
->endUse()
->groupById();
}
Finally, I've got an error in "counting result"
Stack trace:
An exception has been thrown during the rendering of a template ("Unable to execute COUNT statement [SELECT COUNT(*) FROM (SELECT foo.id, foo.title, foo.created_at, foo.updated_at, foo.slug FROM `foo` INNER JOIN `bar` ON (foo.id=bar.foo_id) WHERE bar.id IN (:p1,:p2) GROUP BY foo.id) propelmatch4cnt] [wrapped: Notice: Array to string conversion]") in Admingenerated/PolitizrAdminBundle/Resources/views/FooList/results.html.twig at line 6.
This SQL request throws the error:
every derivated table must have its own alias