我试图连接两个表,但有一个错误:加入的问题:未知记录属性/相关组件
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 }
请告诉我我做错了什么?
未知记录属性/价格“上的”项目“ –
@RomanNewaza var_dump($ item-> priceItem-> getPrice());试试这个 –
$ item-> priceItem是一个数组。我可以打印引用其索引的某些内容:$ item-> priceItem [0] - > getPrice()。如果我循环它,所有值打印一行的项目。由于p.currency_code在WHERE中应该只是一行,对吧? –