2011-07-16 22 views
0

我使用symfony 1.4.11和doctrine。所以架構的一部分:Symfony sfWidgetFormDoctrineChoice with'multiple'=> true

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存儲CATEGORY_ID = 0。當我選擇一個以上的類別,我有錯誤: SQLSTATE [HY093]:無效的參數編號:綁定變量的數量不符令牌

我在谷歌搜索這個錯誤的號碼,但我不知道找到這個決定,而我現在不會在那裏犯錯。謝謝!

回答

1

您定義關係的方式不允許您爲公司選擇多個類別。您可能想要設置多對多關係。 http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:join-table-associations:many-to-many

+0

謝謝你,我改變分類:'{onDelete:CASCADE,地方:CATEGORY_ID,國外:CATEGORY_ID,類型:很多,foreignType:很多}',但我仍然有錯誤... – denys281

+0

我做到了,就像在文檔和所有工作中)謝謝! – denys281

1

就我而言,我不得不修改驗證:

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

+1這也是我的解決方案! – joakimbeng

相關問題