花了最后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.
我以为我得到了我的Inverse并且映射错了。所以(我认为)我已尝试过所有可能的组合,但无济于事。
这是我的映射文件。
//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:我的实体的实体,所以我不会在这里粘贴它们,除非要求它们。所有的制定者和吸气者都在那里。
答案 0 :(得分:3)
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
只是粗略地看了一眼......但这可能是错的。