Filter on composite primary key

Discussion relating to version 1.3.x and 1.4.x

Filter on composite primary key

Postby Lechieux » Tue Apr 10, 2012 12:17 pm

Hi all ! I have a problem when trying to filter on a field which is a part of a composite primary key.

Here is my schema.yml:
Code: Select all
TableauDeBord:
  columns:
    nom:         { type: string(100), notnull: true }
    description: { type: string }
    axe_id:      { type: integer }
  relations:
    Echantillons: { class: Echantillon, local: tableaudebord_id, foreign: echantillon_id, refClass: Publication }
    Indicateurs:  { class: Indicateur, local: tableaudebord_id, foreign: indicateur_id, refClass: EstDansTableauDeBord }
    Axe:          { local: axe_id, foreign: id }

EstDansTableauDeBord:
  columns:
    public:           { type: boolean, default: 0 }
    group_id:         { type: integer, notnull: true }
    tableaudebord_id: { type: integer, notnull: true, primary: true }
    indicateur_id:    { type: integer, notnull: true, primary: true }
  relations:
    TableauDeBord: { onDelete: CASCADE, local: tableaudebord_id, foreign: id }
    Indicateur:    { onDelete: CASCADE, local: indicateur_id, foreign: id }

Indicateur:
  columns:
    nom:         { type: string(100), notnull: true }
    description: { type: string }
    unite_id:    { type: integer, notnull: true }
    requete:     { type: string, notnull: true }
  relations:
    Unite:          { local: unite_id, foreign: id }
    Axes:           { class: Axe, local: indicateur_id, foreign: axe_id, refClass: IndicateurEstDansAxe }
    Secteurs:       { class: Secteur, local: indicateur_id, foreign: secteur_id, refClass: IndicateurEstDansSecteur }
    TableauDeBords: { class: TableauDeBord, local: indicateur_id, foreign: tableaudebord_id, refClass: EstDansTableauDeBord }
    Audits:         { class: Audit, local: indicateur_id, foreign: audit_id, refClass: IndicateurEstDansAudit }

Primary key for "Indicateur" table and "TableauDeBord" table are auto-generated by doctrine (somethink like " id: [type: bigint, primary: true] " ).
In " EstDansTableauDeBord " class, tableaudebord_id and indicateur_id fields are hiddens. So I added the filter widget and validator ( in lib/filter/doctrine/EstDansTableauDeBordFormFilter.class.php ) this way to be able to see see field in my form filter:

Code: Select all
        $this->widgetSchema['tableaudebord_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('TableauDeBord'), 'add_empty' => true));
        $this->validatorSchema['tableaudebord_id'] = new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('TableauDeBord'), 'column' => 'id'));

        $this->widgetSchema['indicateur_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Indicateur'), 'add_empty' => true));
        $this->validatorSchema['indicateur_id'] = new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Indicateur'), 'column' => 'id'));


But the filter does'nt work: It do nothing when executed. If i comment the validator, i got this error: Unexpected extra form field named "tableaudebord_id". Does anybody knows how to make it work, or how to fix this error ?
thx !
Lechieux
Junior Member
 
Posts: 1
Joined: Wed Mar 14, 2012 5:07 pm

Return to symfony 1.3 and 1.4

Who is online

Users browsing this forum: No registered users and 6 guests