Development

#4944 (filter on m2m relations in generated forms)

You must first sign up to be able to contribute.

Ticket #4944 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

filter on m2m relations in generated forms

Reported by: jphilip Assigned to: Jonathan.Wage
Priority: major Milestone: 1.2.0 RC1
Component: sfDoctrinePlugin Version: 1.2.0 BETA2
Keywords: Cc:
Qualification: Unreviewed

Description (Last modified by Jonathan.Wage)

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

Change History

11/17/08 19:22:36 changed by Jonathan.Wage

  • description changed.

11/17/08 22:52:08 changed by Jonathan.Wage

  • status changed from new to closed.
  • resolution set to fixed.

(In [13086]) [1.2] sfDoctrinePlugin: fixes issue with m2m filters (closes #4944)

11/20/08 21:18:56 changed by jphilip

  • status changed from closed to reopened.
  • resolution deleted.

If the expected behavior is for the filters to and each other (what I would expect), the line:

orWhereIn('<?php echo $relation['refTable']->getOption('name') ?>.<?php echo $relation->getForeignFieldName() ?>', $values);

should be:

andWhereIn('<?php echo $relation['refTable']->getOption('name') ?>.<?php echo $relation->getForeignFieldName() ?>', $values);

With orWhereIn, also, the total number of records calculated does not match the query and more rows than expected are displayed.

11/21/08 20:24:53 changed by Jonathan.Wage

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [13210]) [1.2] fixes issue with doctrine filters (closes #4944)

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.