2011-07-16 5 views
0

私はsymfony 1.4.11をdoctrineで使用しています。スキーマの一部:symfony sfWidgetFormDoctrine '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)); 

ユーザーを持っているとき、それはすべてOKです。 私が持っている:

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

そして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

は、私はカテゴリーを変更いただき、ありがとうございます。多くの} '、しかし私はまだエラーがあります... – denys281

+0

私は、文書化とすべての作業のように)ありがとう! – denys281

1

、私はバリデータを変更する必要がありました: `{onDelete:CASCADE、ローカル:CATEGORY_ID、外国:CATEGORY_ID、タイプ:多く、foreignType!

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

+1これも私にとっての解決策でした! – joakimbeng

関連する問題