Php 加入问题:未知记录属性/相关组件

Php 加入问题:未知记录属性/相关组件,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我正在尝试联接两个表,但出现错误: Unknown record property / related component "price" on "Item" 和模式: Item: actAs: Timestampable: ~ columns: name: { type: string(255), notnull: true } product_id: { type: string(255), notnull: true } Price: actAs:

我正在尝试联接两个表,但出现错误:

Unknown record property / related component "price" on "Item" 和模式:

Item: actAs: Timestampable: ~ columns: name: { type: string(255), notnull: true } product_id: { type: string(255), notnull: true } Price: actAs: Timestampable: ~ columns: currency_code: { type: string(3), notnull: true } item_id: { type: integer, notnull: true } price: { type: float, notnull: true } relations: Item: { onDelete: CASCADE, local: item_id, foreign: id, foreignAlias: priceItem } 项目: actAs: 时间标记:~ 柱: 名称:{type:string(255),notnull:true} 产品标识:{type:string(255),notnull:true} 价格: actAs: 时间标记:~ 柱: 货币代码:{type:string(3),notnull:true} 项目id:{type:integer,notnull:true} 价格:{type:float,notnull:true} 关系: 项:{onDelete:CASCADE,local:Item_id,foreign:id,foreignAlias:priceItem} 请告诉我我做错了什么?

价格是价格对象的属性/字段,而不是项目。项目通过别名priceItem与价格关联。然后:


可以找到更多信息。

尝试下面的
var\u dump($item->Price->getPrice())


getPrice()
是Price原则基类的属性,而不是Item类

在“Item”@romanewaza var_dump($Item->priceItem->getPrice())上未知的记录属性/相关组件“Price”;尝试此$item->priceItem是一个数组。我可以打印引用其索引的内容:$item->priceItem[0]->getPrice()。如果我循环它,则为一行项目打印所有值。应仅为一行,因为WHERE中的p.currency_代码,对吗?不要在价格表中使用Innerjoin尝试使用leftJoin。Innerjoin只返回匹配的行,因此应使用它。另外,尝试了leftJoin-同样的事情。如果它返回一条记录,我会感到惊讶。它现在返回多个价格,因为它是正确的join-应该是一行尝试在模式中添加type和foreignType属性。关系:Item:{onDelete:CASCADE,type:one,foreignType:one,local:Item_id,foreignid:id,foreignAlias:priceItem}现在我有一行是Price,但是错误的一行-无论选择了什么货币代码,它总是给我带来第一行。SQL是正确的-我监视mysql.log进行查询。请尝试手动设置主键:item_id:{type:integer,notnull:true,primary:true}货币_代码:{type:string(3),notnull:true,primary:true} Item: actAs: Timestampable: ~ columns: name: { type: string(255), notnull: true } product_id: { type: string(255), notnull: true } Price: actAs: Timestampable: ~ columns: currency_code: { type: string(3), notnull: true } item_id: { type: integer, notnull: true } price: { type: float, notnull: true } relations: Item: { onDelete: CASCADE, local: item_id, foreign: id, foreignAlias: priceItem }
$item->priceItem['price']