运行时:
php app/console doctrine:schema:validate
我收到错误:
[Mapping] FAIL - 实体类' Path \ ToBundle \ Entity \ Variant'映射无效: *引用的列名称' localsku'必须是目标实体类的主键列' Path \ ToBundle \ Entity \ Inventory'。
这里的杀手就是' localsku'确实是一把钥匙。我错过了一些重要的东西吗? 在此先感谢您的帮助,如果我错过了一些关键信息,我会道歉。
变体实体定义为:
Path\ToBundle\Entity\Variant:
type: entity
table: variant
uniqueConstraints:
sku:
columns:
- sku
id:
variantId:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
column: variant_id
generator:
strategy: IDENTITY
fields:
name:
type: string
nullable: false
length: 255
fixed: false
comment: ''
sku:
type: string
nullable: false
length: 255
fixed: false
comment: ''
oneToOne:
inventory:
targetEntity: Inventory
cascade: { }
mappedBy: null
inversedBy: variant
joinColumns:
sku:
referencedColumnName: localsku
orphanRemoval: false
lifecycleCallbacks: { }
库存实体定义为:
Path\ToBundle\Entity\Inventory:
type: entity
table: Inventory
id:
localsku:
type: string
nullable: false
length: 255
fixed: false
comment: ''
id: true
column: LocalSKU
generator:
strategy: IDENTITY
fields:
itemname:
type: string
nullable: true
length: 255
fixed: false
comment: ''
column: ItemName
qoh:
type: integer
nullable: true
unsigned: false
comment: ''
column: QOH
location:
type: string
nullable: true
length: 250
fixed: false
comment: ''
column: Location
barcode:
type: string
nullable: true
length: 25
fixed: true
comment: ''
column: Barcode
oneToOne:
variant:
targetEntity: Variant
cascade: { }
mappedBy: inventory
inversedBy: null
joinColumns:
localsku:
referencedColumnName: sku
orphanRemoval: false
lifecycleCallbacks: { }
对库存的变体实体引用:
/**
* Inventory
*
* @var \Path\ToBundle\Entity\Inventory
*
* @ORM\OneToOne(targetEntity="Path\ToBundle\Entity\Inventory", inversedBy="variant")
* @ORM\JoinColumn(name="sku", referencedColumnName="localsku")
*/
protected $inventory;
库存实体对Variant的引用:
/**
* Variant
*
* @var \Path\ToBundle\Entity\Variant
*
* @ORM\OneToOne(targetEntity="Path\ToBundle\Entity\Variant", inversedBy="inventory")
* @ORM\JoinColumn(name="localsku", referencedColumnName="sku")
*/
protected $variant;
答案 0 :(得分:0)
你的关联映射是错误的。
应该是这样的,假设Variant表有一个" sku"字段。
变体实体:
/**
* Inventory
*
* @var \Path\ToBundle\Entity\Inventory
*
* @ORM\OneToOne(targetEntity="Path\ToBundle\Entity\Inventory", inversedBy="variant")
* @ORM\JoinColumn(name="sku", referencedColumnName="localsku")
*/
protected $inventory;
库存实体:
/**
* Variant
*
* @var \Path\ToBundle\Entity\Variant
*
* @ORM\OneToOne(targetEntity="Path\ToBundle\Entity\Variant", mappedBy="inventory")
*/
protected $variant;
P:我很好奇。您是否对同一实体使用yml配置和注释?我不确定该学说能否合并它们,它有效吗?