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

时间:2011-09-21 06:03:16

标签: php symfony1 symfony-1.4

我正在尝试加入两个表,但出现错误:

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 }

请告诉我,我做错了什么?

2 个答案:

答案 0 :(得分:1)

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

getPrice()是Price doctrine基类的属性,而不是Item Class

答案 1 :(得分:0)

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

$item->priceItem['price']

可以找到更多信息here