2011-09-21 37 views
-1

我试图连接两个表,但有一个错误:加入的问题:未知记录属性/相关组件

 
Unknown record property/related component "price" on "Item" 

这是我的DQL:

$q = Doctrine_Query::create() 
     ->select('i.id, i.product_id, p.price') 
     ->from('Item i') 
     ->innerJoin('i.priceItem p') 
     ->where('i.id = ?', $request->getParameter('id')) 
     ->andWhere('p.currency_code = ?', $request->getParameter('currency_code')); 

    $this->item = $q->execute(); 

    foreach($this->item as $item) { 

     var_dump($item->getId()); 
     var_dump($item->getProductId()); 
     var_dump($item->getPrice()); // This line is causing the error 

    } 

和架构:

 
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 } 

请告诉我我做错了什么?

回答

1

尝试像下面var_dump($item->Price->getPrice());

getPrice()是价格理论基类不是一个项目类

+0

未知记录属性/价格“上的”项目“ –

+0

@RomanNewaza var_dump($ item-> priceItem-> getPrice());试试这个 –

+0

$ item-> priceItem是一个数组。我可以打印引用其索引的某些内容:$ item-> priceItem [0] - > getPrice()。如果我循环它,所有值打印一行的项目。由于p.currency_code在WHERE中应该只是一行,对吧? –

0

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

$item->priceItem['price'] 

更多信息可查询here

+0

现在返回多个价格,因为它是对的加盟财产 - 应该是一排 –

+0

尝试添加*类型*和* foreignType *属性模式。 关系: 货号:{onDelete:CASCADE,类型:one,foreignType:one,local:item_id,foreign:id,foreignAlias:priceItem} – Davide

+0

现在我有一行是Price,但是错了 - 它总是给我带来第一行不管选择什么currency_code。和SQL是正确的 - 我监视mysql.log查询。 –

相关问题