denys281
denys281

Reputation: 2014

Symfony sfWidgetFormDoctrineChoice with 'multiple' => true

I use symfony 1.4.11 with doctrine. So part of schema :

Companies:
  actAs:
    Timestampable: ~
    Sluggable:
      unique: true
      fields: [company]
      canUpdate: false
      builder: [myTools, StripText]
  connection: doctrine
  tableName: companies
  columns:
    company_id:       { type: integer(4), primary: true, notnull: true, autoincrement: true }
    user_id:          { type: int(4)  }
    category_id:      { type: int(4), notnull: true  }
    company:          { type: string(255), notnull: true  }
    address:          { type: string(255), notnull: true  }
    contact_person:   { type: string(255), notnull: true  }
    phone:            { type: string(50), notnull: true }
    fax:              { type: string(50) }
    email:            { type: string(255), notnull: true}
    url:              { type: string(50) }
    about:            { type: string(1000), notnull: true}
    country:          { type: string(255), notnull: true}
    show_ads:         { type: boolean, default: 0 }
    active:           { type: boolean, default: 0 }
    has_company:      { type: boolean, default: 1 }
  relations:
    Owner:            { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser, foreignAlias: Companies }
    Images_companies: { local: company_id, foreign: company_id, type: many, class: Images_companies }
    Categories:       { onDelete: CASCADE, local: category_id, foreign: category_id , type: many, foreignType: one}

Categories:
  actAs:
    I18n:
      fields: [name]
      actAs:
        Sluggable:
          unique: true
          fields: [name]
          canUpdate: true
          builder: [myTools, StripText]
    NestedSet:
      hasManyRoots: true
  connection: doctrine
  tableName: categories
  columns:
    category_id:   { type: integer(4), primary: true, autoincrement: true }
    name:            string(255)

I want that user can choose for company , more than one category. I use sfWidgetFormDoctrineChoice ,so when I have

$this->widgetSchema['category_id'] = new  sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => false));

User can choose only one category , it is all ok. When I have:

$this->widgetSchema['category_id'] = new  sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => true));

And choose only one category from list , in db save category_id = 0 . When I choose more than one category, I have error : SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

I search this error in google, but I don't find the decision, and I do not now where I make something wrong. Thank you!

Upvotes: 0

Views: 1302

Answers (2)

hudony
hudony

Reputation: 21

In my case, I had to modify the validator:

$this->validatorSchema[idapplication] = new sfValidatorDoctrineChoice(
    array(
        model=>'hotteApplication', 'multiple' => true
    )
);

Upvotes: 2

Dziamid
Dziamid

Reputation: 11571

The way you defined your relation does not allow you to choose more than one category for you company. You may want to set up many-to-many relation instead. http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:join-table-associations:many-to-many

Upvotes: 1

Related Questions