Symfony sfWidgetFormDoctrineChoice with'ulti'=>真正

时间:2011-07-16 08:19:53

标签: symfony1 doctrine symfony-1.4 symfony-forms

我使用symfony 1.4.11和doctrine。架构的一部分:

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)

我希望用户可以选择公司,多个类别。我使用sfWidgetFormDoctrineChoice,所以当我有

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

用户只能选择一个类别,一切正常。 当我有:

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

在db save category_id = 0中,从列表中只选择一个类别。当我选择多个类别时,我有错误: SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

我在google中搜索此错误,但我找不到决定,而且我现在不会在哪里犯错。谢谢!

2 个答案:

答案 0 :(得分:1)

您定义关系的方式不允许您为您的公司选择多个类别。您可能希望设置多对多关系。 http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:join-table-associations:many-to-many

答案 1 :(得分:1)

就我而言,我必须修改验证器:

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