我有一个OrderEntity。我第一次只需要表中的三个属性。但现在我还需要两个。 所以我将这两个属性添加到我的实体中:
namespace Stock\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="orders")
*/
class OrderEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="orders_id")
*/
private $ordersId;
/**
* @ORM\Column(type="string", name="order_number")
*/
private $orderNumber;
/**
* @ORM\Column(type="integer", name="stores_id")
*/
private $storesId;
/**
* @ORM\Column(type="string", length=3, name="currency")
*/
private $currency;
/**
* @ORM\Column(type="decimal", precision=6, scale=14, name="currency_value")
*/
private $currencyValue;
public function getOrdersId()
{
return $this->ordersId;
}
public function setOrdersId($ordersId)
{
$this->ordersId = $ordersId;
}
public function getOrderNumber()
{
return $this->orderNumber;
}
public function setOrderNumber($orderNumber)
{
$this->orderNumber = $orderNumber;
}
public function getStoresId()
{
return $this->storesId;
}
public function setStoresId($storesId)
{
$this->storesId = $storesId;
}
public function getCurrency()
{
return $this->currency;
}
public function getCurrencyValue()
{
return $this->currencyValue;
}
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
public function setCurrencyValue($currencyValue)
{
$this->currencyValue = $currencyValue;
return $this;
}
新属性是货币和currencyValue。
$query = $this->getEm()->createQuery(
"SELECT o.ordersId, o.currency FROM "
. "Stock\Entity\OrderEntity o WHERE "
. "o.ordersId ='".$orderId."'"
);
如果我想使用较新的属性创建查询,我得到了一个QueryException:
[Semantical Error] line 0, col 21 near 'currency FROM': Error: Class Stock\Entity\OrderEntity has no field or association named currency
我不完全明白问题出在哪里!