2

テーブル間に多くの関係があるフォームを作成するのに問題があります。下の図で見ることができる関係の構造:テーブル間の関係

YML での私の関係:

######### Products.orm.yml #########

   type: entity
   table: products
   fields:
   ...
   lifecycleCallbacks: {  }
   oneToMany:
   productCombinations:
      targetEntity: ProductsCombinations
      mappedBy: product

######### ProductsCombinations.orm.yml #########

   type: entity
   table: products_combinations
   fields:
   ...
   lifecycleCallbacks: {  }
   oneToMany:
      productAttributes:
        targetEntity: ProductsAttributesJoin
        mappedBy: productCombinations
   manyToOne:
      product:
        targetEntity: Products
        inversedBy: productCombinations
        joinColumn:
          name: product_id
          referencedColumnName: id

######### ProductsAttributesJoin.orm.yml ########

type: entity
table: null
fields:
    combinationID:
        type: bigint
        column: combination_id
        id: true
        generator:
            strategy: NONE
    attributeID:
        type: bigint
        id: true
        generator:
            strategy: NONE
        column: attribute_id
lifecycleCallbacks: {  }
manyToOne:
    productCombinations:
      targetEntity: ProductsCombinations
      inversedBy: productAttributes
      joinColumn:
        name: combination_id
        referencedColumnName: combination_id
    attributes:
      targetEntity: Attributes
      inversedBy: productAttributesJoin
      joinColumn:
        name: attribute_id
        referencedColumnName: id

######### Attributes.orm.yml #########

   type: entity
   table: products_attributes
   fields:
   ...
   lifecycleCallbacks: {  }
   oneToMany:
      productAttributesJoin:
        targetEntity: ProductsAttributesJoin
        mappedBy: attributes
   manyToOne:
       productAttributesDefinitions:
         targetEntity: AttributesDefinitions
         inversedBy: productAttributes
         joinColumn:
           name: attribute_id
           referencedColumnName: id

######### AttributesDefinitions.orm.yml #########

   type: entity
   table: products_attributes_definitions
   fields:
   ...
   lifecycleCallbacks: {  }
   oneToMany:
      productAttributes:
        targetEntity: Attributes
        mappedBy: productAttributesDefinitions
   manyToOne:
       productAttributesDefinitions:
         targetEntity: AttributesDefinitions
         inversedBy: productAttributes
         joinColumn:
           name: attribute_id
           referencedColumnName: id

私が知っていることは次のとおりです。 epos_wrong

[新規追加] をクリックすると、ProductsCombinations のフィールドがポップアップ表示されますが、それらを入力して [保存] を押すと、product_id が null であるというエラーが表示されます (ただし、Products から取得する必要があります)。

また、私がやりたいことは次のようなものです: ここに画像の説明を入力

また、管理ディレクトリからのコードのビット:

###### ProductsView.php ######

$formMapper->with('Attributes')
            ->add('productCombinations',  'sonata_type_collection')
        ->end()

###### ProductsCombinations.php ######

    $formMapper
        ->with('General')
            ->(some main fields from productCombinations)
            ->add('productAttributes', 'sonata_type_collection', array(), array(
            'edit' => 'inline',
            'inline' => 'table',
            'sortable'  => 'position'
        ))

###### ProductsAttributesJoin.php ######

    $formMapper
        ->with('General')
            ->add('attributes', 'sonata_type_model')
        ->end()
    ;
4

1 に答える 1