映射//实体和//实体彼此不一致 - Symfony2 / Doctrine2 [英] The mappings //Entity and //Entity are inconsistent with each other - Symfony2/Doctrine2
问题描述
当我尝试验证我的数据库时,我收到此错误:
[映射] FAIL - 实体类'BC \InventoryBundle\Entity\ProductRecipe'映射无效:
*映射BC \InventoryBundle\Entity\ProductRecipe#products和BC \InventoryBundle\Entity\Products#recipes彼此不一致。
*映射BC \InventoryBundle\Entity\ProductRecipe#recipes和BC \InventoryBundle\Entity\Recipes#产品彼此不一致。
[映射] FAIL - 实体类'BC \InventoryBundle\Entity\Products'映射无效:
*映射BC \InventoryBundle\Entity\Products #recipes和BC\InventoryBundle\Entity\ProductRecipe#配方彼此不一致。
[映射] FAIL - 实体类'BC \InventoryBundle\Entity\Recipes'映射无效:
*映射BC \InventoryBundle\Entity\Recipes #products和BC \InventoryBundle\Entity\ProductRecipe#产品彼此不一致。
我以为我得到了我的反向和映射错误。所以(我想)我已经尝试了所有可能的组合,但无济于事。
这是我的映射文件。
// Recipe.orm.yml
oneToMany:
产品:
mappedBy:productsProductRecipe
cascade:[all]
//Products.orm.yml
oneToMany:
食谱:
targetEntity:ProductRecipe
mappedBy:recipes
cascade:[all]
//ProductRecipe.orm.yml
BC \InventoryBundle\Entity\ProductRecipe:
type:entity
表:ProductRecipe
repositoryClass:BC \InventoryBundle\Entity\ProductRecipeRepository
id:
id:
类型:整数
生成器:{strategy:AUTO}
fields:
ammount:
type:decimal
presision:10
scale:2
manyToOne:
product:
targetEntity:Products
inversedBy:recipes
joinColumn:
名称:product_id
referencedColumnName:id
食谱:
targetEntity:食谱
inversedBy:products
joinColumn:
name:recipe_id
referencedColumnName:id
我一直在使用Doctrine:Generate:Entities为我的实体,所以我不会将它们粘贴在这里,除非问他们所有的设定者和吸烟者都在那里。
Recipe.orm.yml
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ :[all]
Products.orm.yml \\应重命名为单数,您的关系也适用于产品
oneToMany:
食谱:
targetEntity:ProductRecipe
mappedBy:products //以前的recipes
cascade:[all]
ProductRecipe.orm.yml
BC \InventoryBundle\Entity\ProductRecipe:
类型:实体
表:ProductRecipe
repositoryClass:BC \InventoryBundle\Entity\ProductRecipeRepository
id:
id:
type:integer
生成器:{strategy:AUTO}
fields:
amount://以前的ammount
type:decimal
presision :10
比例:2
manyToOne:
产品:
targetEntity:Product
//产品被正确命名,但食谱是单数
//为了统一起见
inversedBy:recipes
joinColumn:
name:product_id
referencedColumnName:id
食谱:
targetEntity:食谱
//以前的食谱,不正确的实体名称
inversedBy:products
joinColumn:
name:recipe_id
referencedColumnName:id
只是粗略一瞥...可能是错误的。
Have spent literally the last 2 hours trying to fix this issue. I'm sure it's something stupid I am overlooking but It's properly got me stuck.
I am getting this error when I try and validate my database :
[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.
I thought I had got my Inverse and Mapped by's wrong. So (I think) I have tried every possible combination but to no avail.
Here's my mapping files.
//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
I have been using Doctrine:Generate:Entities for my entities so I won't paste them here unless asked for them. All the setters and getters are there.
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
Just at a cursory glance... It could be wrong though.
这篇关于映射//实体和//实体彼此不一致 - Symfony2 / Doctrine2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!