In a generated list view, the default filter form shows a sfWidgetFormDoctrineSelectMany for m2m relations, but I could not get it to filter correctly.
I am having to override the method:
addxxxListColumnQuery(Doctrine_Query $query, $field, $values) where xxx is the name of the relation because it filters on the wrong side of the relation and the whereIn clause has a or instead of and.
For example, for the filter to work as expected, I have to override the generated method:
public function addstudiesListColumnQuery(Doctrine_Query $query, $field, $values)
{
if (!is_array($values))
{
$values = array($values);
}
if (!count($values))
{
return;
}
$query->leftJoin('r.assParticipation assParticipation')
->orWhereIn('assParticipation.participant_id', $values);
}
With:
public function addstudiesListColumnQuery(Doctrine_Query $query, $field, $values)
{
if (!is_array($values))
{
$values = array($values);
}
if (!count($values))
{
return;
}
$query->leftJoin('r.assParticipation assParticipation')
->andWhereIn('assParticipation.study_id', $values);
}
The model:
tblParticipant:
columns:
id:
type: integer(4)
primary: true
autoincrement: true
.......
relations:
studies:
class: tblStudy
refClass: assParticipation
local: participant_id
foreign: study_id
foreignAlias: participants
tblStudy:
columns:
id:
type: integer(4)
primary: true
autoincrement: true
name:
type: string(128)
notnull: true
.......
assParticipation:
columns:
id:
type: integer(4)
primary: true
autoincrement: true
participant_id:
type: integer(4)
notnull: true
study_id:
type: integer(4)
notnull: true
study_code:
type: string(10)
notnull: true
relations:
participant:
class: tblParticipant
local: participant_id
foreign: id
foreignAlias: participations
study:
class: tblStudy
local: study_id
foreign: id
foreignAlias: participations