我花了两个小时试图解决这个问题。我确信这是我忽视的愚蠢的事情,但它确实让我卡住了。
当我尝试验证我的数据库时,我得到这个错误:
[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作为我的实体,所以我不会在这里粘贴它们,除非被要求。所有的setter和getter都在那里
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
只是粗略地看了一眼…