1

これまで私はあなたの答えで解決策を見つけていたので、これが私の最初の投稿です...

翻訳可能なフィールドを持つ 3 つのエンティティ (Bike、Category、および Extra) があります。symfony に Translatable Extension があることは知っていますが、少し遅れて発見したため、ソリューションは常に機能しています。

問題は、他に 3 つのテーブル (BikeI18N、CategoryI18N、および ExtraI18N) があることです。これらのテーブルは、列 bike_id (たとえば) に関連付けられています。ここに、Bike と Category のスキーマとそれらの I18N のテーブルがあります。

自転車:

BEM\BikeBundle\Entity\Bike:
type: entity
table: null
fields:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
    marca:
        type: string
        length: 255
    model:
        type: string
        length: 255
    preu1Dia:
        type: float
        column: preu_1dia
    [...]
manyToOne:
  category:
    targetEntity: BEM\CategoryBundle\Entity\Category
    inversedBy: bikes 
oneToMany:
  translation:
    targetEntity: BikeI18N
    mappedBy: bike
    cascade: [persist]        
  pedals:
    targetEntity: Pedal
    mappedBy: bike
  talles:
    targetEntity: Talla
    mappedBy: bike
manyToMany:
  accessoris:
    targetEntity: Accessori
    inversedBy: bikes      
lifecycleCallbacks: {  }

バイクI18N:

BEM\BikeBundle\Entity\BikeI18N:
type: entity
table: null
fields:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
    descripcio:
        type: text
    locale:
        type: string
        length: '2'
manyToOne:
  bike:
    targetEntity: Bike
    inversedBy: translation  
    joinColumn:
      bike_id:
        referencedColumnName: id        
lifecycleCallbacks: {  }

カテゴリー:

BEM\CategoryBundle\Entity\Category:
type: entity
table: null
repositoryClass: BEM\CategoryBundle\Repository\CategoryRepository
fields:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
oneToMany:
  translation:
    targetEntity: CategoryI18N
    mappedBy: category
    cascade: [persist]
  bikes:
    targetEntity: BEM\BikeBundle\Entity\Bike
    mappedBy: category
lifecycleCallbacks: {  }

そして最後に CategoryI18N:

BEM\CategoryBundle\Entity\CategoryI18N:
type: entity
table: null
fields:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
    categoryId:
        type: integer
        column: category_id
    locale:
        type: string
        length: '2'
    translation:
        type: string
        length: 255
manyToOne:
  category:
    targetEntity: Category
    inversedBy: translation
    joinColumn:
      category_id:
        referencedColumnName: id        
lifecycleCallbacks: {  }

私の「新しい」フォームには、4 つの CategoryI18N フォームが埋め込まれたカテゴリ フォームがあります。正常に動作します。問題は、私が同じことをしたとしても、Bike と BikeI18N がそうではないことです。

書き込む$translation->setAccessori($this);、選択フィールドに渡されたエンティティを管理する必要があるBike::addTranslation(BikeI18N $translation)というエラーが表示されます。たぶんエンティティマネージャーでそれらを永続化しますか? .

フォームを記述しない$translation->setAccessori($this); と保存されますが、関係が失われるか、DB を に設定するとnot_nullable bike_idエラーが発生します。

私にとって意味をなさない最も驚くべきことsetCategory($this)は、クラス Category の addTranslation 内にあることです...何かアイデアはありますか?

4

1 に答える 1

0

問題を解決しました。

考えは、私の BikeI18N フォーム ビルダーにありました。

    class BikeI18NType extends AbstractType
    {
       public function buildForm(FormBuilderInterface $builder, array $options)
         {
            $builder
            ->add('descripcio')
            ->add('locale', 'hidden')
            //->add('bike', 'hidden')
           ;
         }
     }

バイクの追加をコメントアウトすると、問題は解決しました。

読んでくれてありがとう!

于 2013-10-27T18:32:58.327 に答える