繁体   English   中英

// Entity和// Entity的映射彼此不一致-Symfony2 / Doctrine2

[英]The mappings //Entity and //Entity are inconsistent with each other - Symfony2/Doctrine2

从字面上看,过去2个小时中一直在尝试解决此问题。 我确定这是我忽略的愚蠢做法,但这确实使我陷入困境。

尝试验证数据库时出现此错误:

 [Mapping]  FAIL - The entity-class 'BC\InventoryBundle\Entity\ProductRecipe' mapping is     invalid:
 * The mappings BC\InventoryBundle\Entity\ProductRecipe#products and BC\InventoryBundle\Entity\Products#recipes are incosistent with each other.
 * The mappings BC\InventoryBundle\Entity\ProductRecipe#recipes and BC\InventoryBundle\Entity\Recipes#products are incosistent with each other.

[Mapping]  FAIL - The entity-class 'BC\InventoryBundle\Entity\Products' mapping is invalid:
* The mappings BC\InventoryBundle\Entity\Products#recipes and BC\InventoryBundle\Entity\ProductRecipe#recipes are incosistent with each other.

[Mapping]  FAIL - The entity-class 'BC\InventoryBundle\Entity\Recipes' mapping is invalid:
* The mappings BC\InventoryBundle\Entity\Recipes#products and BC\InventoryBundle\Entity\ProductRecipe#products are incosistent with each other.

我以为我的逆和映射是错误的。 所以(我认为)我尝试了所有可能的组合,但无济于事。

这是我的映射文件。

//Recipe.orm.yml
   oneToMany:
    products:
      mappedBy: productsProductRecipe
      cascade: ["all"]

//Products.orm.yml
   oneToMany:
    recipes:
      targetEntity: ProductRecipe
      mappedBy: recipes
      cascade: ["all"]

//ProductRecipe.orm.yml
BC\InventoryBundle\Entity\ProductRecipe:
type: entity
table: ProductRecipe
repositoryClass: BC\InventoryBundle\Entity\ProductRecipeRepository

id:
    id:
        type: integer
        generator: { strategy: AUTO }
fields:
    ammount:
        type: decimal
        presision: 10
        scale: 2

   manyToOne:
    products:
      targetEntity: Products
      inversedBy: recipes
      joinColumn:
        name: product_id
        referencedColumnName: id
    recipes:
      targetEntity: Recipes
      inversedBy: products
      joinColumn:
        name: recipe_id
        referencedColumnName: id

我一直在为我的实体使用Doctrine:Generate:Entities,因此除非有要求,否则我不会将其粘贴到此处。 所有的设置者和获取者都在那里。

Recipe.orm.yml

   oneToMany:
        products:
            targetEntity: ProductRecipe // Not present before
            mappedBy: recipes // Previously "productsProductRecipe"
            cascade: ["all"]

Products.orm.yml \\\\ Should rename for singular, also your relation is for Product

    oneToMany:
        recipes:
            targetEntity: ProductRecipe
            mappedBy: products // Previously "recipes"
            cascade: ["all"]

ProductRecipe.orm.yml

BC\InventoryBundle\Entity\ProductRecipe:
    type: entity
    table: ProductRecipe
    repositoryClass: BC\InventoryBundle\Entity\ProductRecipeRepository

    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        amount: // Previously "ammount"
            type: decimal
            presision: 10
            scale: 2

    manyToOne:
        products:
            targetEntity: Product
                // "Products" is named correctly but recipe is singular
                // so for the sake of uniformity 
            inversedBy: recipes
            joinColumn:
                name: product_id
                referencedColumnName: id
        recipes:
            targetEntity: Recipe 
                // Previously "Recipes", incorrect entity name
            inversedBy: products
            joinColumn:
                name: recipe_id
                referencedColumnName: id

粗略地看...虽然可能是错误的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM