I’m trying to join two tables, but having an error:
Unknown record property / related component "price" on "Item"
This is my 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
}
and schema:
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 }
Please tell me what am I doing wrong?
try like below
var_dump($item->Price->getPrice());getPrice()is property of the Price doctrine base class not a Item Class