2012-02-12 16 views
1

外来キーを母テーブルに保存するための解決策を見つけるのに何時間もかかります。 私はsymfony 1.4で埋め込み関係を使用しようとしています(私もahDoctrineEasyEmbeddedRelationsPluginを持っています)。外部キー埋め込みリレーションで保存しない

私はsymfonyのドキュメントを読んだとき、ここ

http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms

スキーマは次のとおりです。

Product: 
    columns: 
    name:   { type: string(255), notnull: true } 
    price:   { type: decimal, notnull: true } 
ProductPhoto: 
    columns: 
    product_id:  { type: integer } 
    filename:  { type: string(255) } 
    caption:  { type: string(255), notnull: true } 
    relations: 
    Product: 
     alias:  Product 
     foreignType: many 
     foreignAlias: Photos 
     onDelete:  cascade 

embedRelationは、次のようになります。私はできません私の場合は

// lib/form/doctrine/ProductForm.class.php 
public function configure() 
{ 
    // ... 

    $this->embedRelation('Photos'); 
} 

それは反対です、製品には関係の鍵がありますそのようなAVE何か:

Product: 
    columns: 
    name:   { type: string(255), notnull: true } 
    price:   { type: decimal, notnull: true } 
    photoid:  { type: integer } 
    ownerid:  { type: integer } 
    relations: 
    Photo: 
     local:  photoid 
     foreign:  id 
     type:   one 
    Owner: 
     local:  ownerid 
     foreign:  id 
     type:   one 
Photo: 
    columns: 
    id :   { type: integer } 
    filename:  { type: string(255) } 
    caption:  { type: string(255), notnull: true } 
owner: 
    columns: 
    id :   { type: integer } 
    firstname:  { type: string(255) } 
    lastname:  { type: string(255), notnull: true } 

とembedRelation:

// lib/form/doctrine/ProductForm.class.php 
public function configure() 
{ 
    // ... 
    $this->embedRelation('Photo'); 
    $this->embedRelation('Owner'); 
} 

そして、そこの形で更新するために、名前や価格などの製品に関連するウィジェットだけの情報が写真と所有者のテーブルから来ていません。

新しいフォームを保存すると、写真とオーナーオブジェクトがテーブルに保存され、IDがシーケンスで作成されます。問題は、製品が決して更新されないことです。 photoidとowneridはまだnullのままです。 埋め込みフォームに似ています。写真と所有者はルートフォームの後に保存されます。

この場合、埋め込みを使用することはできますか? ルートフォームがprocessFormに保存されているときに、Productテーブルの外部キーを保存する正しい方法は何ですか? トリックは何ですか? PhotoForm.class.phpの使用では

答えて

0

:「sfForm :: useFields()は1.3 symfonyのための新しい機能です:ドキュメントが言うよう

$this->useFields(array('filename', 'caption')); 

そしてdocumentation

+0

usefieldsを読んで表示するためであります開発者は、フォームで使用するフィールドと表示する順序を正確に指定することができます。隠しフィールド以外はすべてフォームから削除されます。 2つの表のIDはフォームに隠されています。私が持っている問題は、表示用ではなく、外部キーを保存することです。 – philcaba

関連する問題