Symfony Generator, Doctrine, and M: N Forms

Possible Duplicate:
Symfony Generator Forms, Doctrine, and M: N Relationships

I have a basic setup of M: N with three tables: candidate, position and candidate. Here is my best raven-kick ERF kick with just the text

[candiate]-||------|<[candidate_position]>|------||-[position]

What I'm trying to accomplish is the following: When a candidateis created or edited, the form will contain an array of flags of all available positions for assignment to the candidate.

In the normal world of web application development, it is really very simple. But I'm trying to improve my competency with the symfony key generator. That's what i still have

<strong> applications / backends / modules / condidate / configurations / generator.yml

generator:
  class: sfDoctrineGenerator
  param:
    model_class:           Candidate
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          candidate
    with_doctrine_route:   true
    actions_base_class:    sfActions

    config:
      actions: ~
      fields:  
    first_name: { label: First Name }
    last_name:  { label: Last Name }
    created_at: { label: Created On }
    positions:  {}
      list:    
    sort:  [last_name, asc]
      filter:  ~
      form:    
    display:
      "User": [first_name, last_name]
      "Applying For": [positions]
    fields :
      hide:  [created_at]
      edit:    ~
      new:     ~

Library / form / teaching / candidateForm.class.php

class candidateForm extends BasecandidateForm
{
  public function configure()
  {
    unset( $this['created_at'] );

    $this->widgetSchema['positions'] = new sfWidgetFormDoctrineChoice(
      array( 'multiple' => true, 'model' => 'Position', 'renderer_class' => 'sfWidgetFormSelectCheckbox' )
    );

    $this->validatorSchema['positions'] = new sfValidatorDoctrineChoice(
      array( 'multiple' => true, 'model' => 'Position', 'min' => 1 )
    );
  }
}

//schema.yml

candidate:
  columns:
    id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
      autoincrement: true
    first_name:
      type: string(45)
      notnull: true
    last_name:
      type: string(45)
      notnull: true
    created_at:
      type: integer(4)
      unsigned: true

position:
  columns:
    id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
      autoincrement: true
    name:
      type: string(45)

candidatePosition:
  tableName: candidate_position
  columns:
    candidate_id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
    position_id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
  relations:
    candidate:
      class: candidate
      local: candidate_id
      foreign: id
      foreignAlias: candidate_positions
    position:
      class: position
      local: position_id
      foreign: id
      foreignAlias: candidate_positions
  indexes:
    fk_candidate_position_candidate1:
      fields: [candidate_id]
    fk_candidate_position_position1:
      fields: [position_id]

! =/

, . (?) (lib/model/doctrine/candid.class.php), , . , [] candidate::save()

  • PHP 5.2.x
  • symfony 1.4.3
+3
2

, db, build-schema. , M: N. schema.yml , , .

candidate:
  columns:
    id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
      autoincrement: true
    first_name:
      type: string(45)
      notnull: true
    last_name:
      type: string(45)
      notnull: true
    created_at:
      type: integer(4)
      unsigned: true
  relations:
    Position:
       refClass: candidatePosition
       local: candidate_id
       foreign: position_id

position:
  columns:
    id:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
      autoincrement: true
    name:
      type: string(45)
  relations:
    Candidate:
       refClass: candidatePosition
       local: position_id
       foreign: candidate_id
+1
//schema.yml
Candidate:
  columns: ~
  relations:
    Position:
      alias: Positions
      refClass: CandidatePosition
      local: candidate_id
      foreign: position_id

Position:
  columns: ~
  relations:
    Candidate:
      alias: Candidates
      refClass: CandidatePosition
      local: position_id
      foreign: candidate_id

CandidatePosition:
  columns:
    candidate_id:
      type: integer(4)
      primary: true
    position_id:
      type: integer(4)
      primary: true

//CandidateForm class
  public function configure()
  {
    $this->getWidget('positions_list')->setOption('expanded', true);
  }

default generator.yml

0

Source: https://habr.com/ru/post/1796362/


All Articles