我正在尝试加入两个表,但出现错误:
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 }
请告诉我,我做错了什么?
答案 0 :(得分:1)
尝试以下var_dump($item->Price->getPrice());
getPrice()
是Price doctrine基类的属性,而不是Item Class
答案 1 :(得分:0)