我正在使用原则为电子商务网站构建运输系统。为此,我在结帐时根据产品和区域数据获得了适当的运输方式和价格。
我正在将以下代码与查询构建器一起使用:
$shippingPriceReccords
= $this->em->createQueryBuilder()
->select('price')
->from('OrderShippingPrice', 'price')
->innerJoin('OrderShippingMethod', 'method', 'price.fkOrderShippingMethod = method.id')
->innerJoin('OrderShippingMethodRegionMapping', 'map', 'map.fkOrderShippingMethod = method.id')
->where('price.fkProductType = :fkProductType')
->andwhere('price.fkBrand = :fkBrand')
->andwhere('map.fkRegion = :fkRegion')
->setParameters([
'fkProductType' => $fkProductType,
'fkBrand' => $fkBrand,
'fkRegion' => $regionID,
])
->getQuery()
->setFetchMode("OrderCart", "address", DoctrineORMMappingClassMetadata::FETCH_EAGER)
->getResult();
但这失败了,给了我这个错误:
[Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN'
来自上述查询的 DQL:
SELECT price FROM OrderShippingPrice price INNER JOIN OrderShippingMethod method INNER JOIN OrderShippingMethodRegionMapping map WHERE price.fkProductType = :fkProductType AND price.fkBrand = :fkBrand AND map.fkRegion = :fkRegion
订单运费价格包含:
<?php
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsCollection;
use DoctrineCommonCollectionsArrayCollection;
/**
* OrderShippingPrice
*
* @ORMTable(name="orderShippingPrice")
* @ORMEntity
*/
class OrderShippingPrice
{
/**
*
* Normal string / int object data
*
*/
/**
* @var int
*
* @ORMColumn(name="id", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var int
*
* @ORMColumn(name="fkOrderShippingMethod", type="integer", nullable=true)
*/
private $fkOrderShippingMethod = '0';
/**
* @var float
*
* @ORMColumn(name="price", type="float", precision=7, scale=2, nullable=false)
*/
private $price = '0.00';
/**
* @var int
*
* @ORMColumn(name="fkProductType", type="integer", nullable=true)
*/
private $fkProductType = '0';
/**
* @var int
*
* @ORMColumn(name="fkBrand", type="integer", nullable=true)
*/
private $fkBrand = '0';
/**
* @var string
*
* @ORMColumn(name="isExpeditable", type="string", length=16, nullable=false)
*/
private $isExpeditable = '0';
/**
* @var string
*
* @ORMColumn(name="expediteDescription", type="text", length=65535, nullable=false)
*/
private $expediteDescription = '';
/**
* @var string
*
* @ORMColumn(name="showLiftGateOption", type="string", length=16, nullable=false)
*/
private $showLiftGateOption = '0';
/**
* @var string
*
* @ORMColumn(name="showDestinationOption", type="string", length=16, nullable=false)
*/
private $showDestinationOption = '0';
/**
* @var string
*
* @ORMColumn(name="productNotAvailable", type="string", length=16, nullable=false)
*/
private $productNotAvailable = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* Many OrderShippingPrices have One OrderShippingMethod.
* @ORMManyToOne(targetEntity="OrderShippingMethod", fetch="EAGER")
* @ORMJoinColumn(name="fkOrderShippingMethod", referencedColumnName="id")
**/
private $orderShippingMethod;
/**
* Get orderOrderShippingMethod
*
* @return OrderShippingMethod
*/
public function getOrderShippingMethod()
{
return $this->orderShippingMethod;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set fkOrderShippingMethod
*
* @param string $fkOrderShippingMethod
*
* @return OrderCart
*/
public function setFkOrderShippingMethod($fkOrderShippingMethod)
{
$this->fkOrderShippingMethod = $fkOrderShippingMethod;
return $this;
}
/**
* Get fkOrderShippingMethod
*
* @return string
*/
public function getFkOrderShippingMethod()
{
return $this->fkOrderShippingMethod;
}
/**
* Set price
*
* @param string $price
*
* @return OrderCart
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set fkProductType
*
* @param string $fkProductType
*
* @return OrderCart
*/
public function setFkProductType($fkProductType)
{
$this->fkProductType = $fkProductType;
return $this;
}
/**
* Get fkProductType
*
* @return string
*/
public function getFkProductType()
{
return $this->fkProductType;
}
/**
* Set fkBrand
*
* @param string $fkBrand
*
* @return OrderCart
*/
public function setFkBrand($fkBrand)
{
$this->fkBrand = $fkBrand;
return $this;
}
/**
* Get fkBrand
*
* @return string
*/
public function getFkBrand()
{
return $this->fkBrand;
}
/**
* Set isExpeditable
*
* @param string $isExpeditable
*
* @return OrderCart
*/
public function setIsExpeditable($isExpeditable)
{
$this->isExpeditable = $isExpeditable;
return $this;
}
/**
* Get isExpeditable
*
* @return string
*/
public function getIsExpeditable()
{
return $this->isExpeditable;
}
/**
* Set expediteDescription
*
* @param string $expediteDescription
*
* @return OrderCart
*/
public function setExpediteDescription($expediteDescription)
{
$this->expediteDescription = $expediteDescription;
return $this;
}
/**
* Get expediteDescription
*
* @return string
*/
public function getExpediteDescription()
{
return $this->expediteDescription;
}
/**
* Set showLiftGateOption
*
* @param string $showLiftGateOption
*
* @return OrderCart
*/
public function setShowLiftGateOption($showLiftGateOption)
{
$this->showLiftGateOption = $showLiftGateOption;
return $this;
}
/**
* Get showLiftGateOption
*
* @return string
*/
public function getShowLiftGateOption()
{
return $this->showLiftGateOption;
}
/**
* Set showDestinationOption
*
* @param string $showDestinationOption
*
* @return OrderCart
*/
public function setShowDestinationOption($showDestinationOption)
{
$this->showDestinationOption = $showDestinationOption;
return $this;
}
/**
* Get showDestinationOption
*
* @return string
*/
public function getShowDestinationOption()
{
return $this->showDestinationOption;
}
/**
* Set productNotAvailable
*
* @param string $productNotAvailable
*
* @return OrderCart
*/
public function setProductNotAvailable($productNotAvailable)
{
$this->productNotAvailable = $productNotAvailable;
return $this;
}
/**
* Get productNotAvailable
*
* @return string
*/
public function getProductNotAvailable()
{
return $this->productNotAvailable;
}
}
订单运输方法包含:
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsCollection;
use DoctrineCommonCollectionsArrayCollection;
/**
* OrderShippingMethod
*
* @ORMTable(name="orderShippingMethod")
* @ORMEntity
*/
class OrderShippingMethod
{
/**
*
* Normal string / int object data
*
*/
/**
* @var int
*
* @ORMColumn(name="id", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="name", type="text", length=255, nullable=false)
*/
private $name = '';
/**
* @var string
*
* @ORMColumn(name="carrier", type="string", length=32, nullable=false)
*/
private $carrier = '';
/**
* @var string
*
* @ORMColumn(name="bvCode", type="string", length=32, nullable=false)
*/
private $bvCode = '';
/**
* @var string
*
* @ORMColumn(name="trackingUrl", type="string", length=255, nullable=true)
*/
private $trackingUrl = '';
/**
* @var int
*
* @ORMColumn(name="minimumLeadTime", type="integer", nullable=false)
*/
private $minimumLeadTime = '0';
/**
* @var int
*
* @ORMColumn(name="maximumLeadTime", type="integer", nullable=false)
*/
private $maximumLeadTime = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* @ORMOneToMany(targetEntity="OrderShippingMethodRegionMapping", mappedBy="orderShippingMethod", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER")
* @var orderShippingMethodRegionMappings[]
**/
public $orderShippingMethodRegionMappings;
/**
* Constructor
*
* Create array for collection of orderShippingMethodRegionMappings
*/
public function __construct()
{
$this->orderShippingMethodRegionMappings = new ArrayCollection();
}
/**
* Get orderShippingMethodRegionMapping(s)
*
* @return array
*/
public function getOrderShippingMethodRegionMappings()
{
return $this->orderShippingMethodRegionMappings;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param int $name
*
* @return OrderCart
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return int
*/
public function getName()
{
return $this->name;
}
/**
* Set carrier
*
* @param string $carrier
*
* @return OrderCart
*/
public function setCarrier($carrier)
{
$this->carrier = $carrier;
return $this;
}
/**
* Get carrier
*
* @return string
*/
public function getCarrier()
{
return $this->carrier;
}
/**
* Set bvCode
*
* @param string $bvCode
*
* @return OrderCart
*/
public function setBvCode($bvCode)
{
$this->bvCode = $bvCode;
return $this;
}
/**
* Get bvCode
*
* @return string
*/
public function getBvCode()
{
return $this->bvCode;
}
/**
* Set trackingUrl
*
* @param string $trackingUrl
*
* @return OrderCart
*/
public function setTrackingUrl($trackingUrl)
{
$this->trackingUrl = $trackingUrl;
return $this;
}
/**
* Get trackingUrl
*
* @return string
*/
public function getTrackingUrl()
{
return $this->trackingUrl;
}
/**
* Set minimumLeadTime
*
* @param string $minimumLeadTime
*
* @return OrderCart
*/
public function setMinimumLeadTime($minimumLeadTime)
{
$this->minimumLeadTime = $minimumLeadTime;
return $this;
}
/**
* Get minimumLeadTime
*
* @return string
*/
public function getMinimumLeadTime()
{
return $this->minimumLeadTime;
}
/**
* Set maximumLeadTime
*
* @param string $maximumLeadTime
*
* @return OrderCart
*/
public function setMaximumLeadTime($maximumLeadTime)
{
$this->maximumLeadTime = $maximumLeadTime;
return $this;
}
/**
* Get maximumLeadTime
*
* @return string
*/
public function getMaximumLeadTime()
{
return $this->maximumLeadTime;
}
}
OrderShippingMethodRegionMapping包含:
<?php
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsCollection;
use DoctrineCommonCollectionsArrayCollection;
/**
* OrderShippingMethodRegionMapping
*
* @ORMTable(name="orderShippingMethodRegionMapping")
* @ORMEntity
*/
class OrderShippingMethodRegionMapping
{
/**
*
* Normal string / int object data
*
*/
/**
* @var int
*
* @ORMColumn(name="id", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var int
*
* @ORMColumn(name="fkOrderShippingMethod", type="integer")
*/
private $fkOrderShippingMethod = '0';
/**
* @var int
*
* @ORMColumn(name="fkOrderRegion", type="integer")
*/
private $fkOrderRegion = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* Many OrderShippingPrices have One OrderShippingMethod.
* @ORMManyToOne(targetEntity="OrderShippingMethod", inversedBy="orderShippingMethodRegionMappings")
* @ORMJoinColumn(name="fkOrderShippingMethod", referencedColumnName="id")
**/
private $orderShippingMethod;
/**
* Sets a new OrderShippingMethod and cleans the previous one if set
* @param OrderShippingMethod
*/
public function setOrderShippingMethod(OrderShippingMethod $orderShippingMethod)
{
$this->orderShippingMethod = $orderShippingMethod;
}
/**
* Get orderOrderShippingMethod
*
* @return OrderShippingMethod
*/
public function getOrderShippingMethod()
{
return $this->orderShippingMethod;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set fkOrderShippingMethod
*
* @param int $fkOrderShippingMethod
*
* @return OrderCart
*/
public function setFkOrderShippingMethod($fkOrderShippingMethod)
{
$this->fkOrderShippingMethod = $fkOrderShippingMethod;
return $this;
}
/**
* Get fkOrderShippingMethod
*
* @return int
*/
public function getFkOrderShippingMethod()
{
return $this->fkOrderShippingMethod;
}
/**
* Set fkOrderRegion
*
* @param int $fkOrderRegion
*
* @return OrderCart
*/
public function setFkOrderRegion($fkOrderRegion)
{
$this->fkOrderRegion = $fkOrderRegion;
return $this;
}
/**
* Get fkOrderRegion
*
* @return int
*/
public function getFkOrderRegion()
{
return $this->fkOrderRegion;
}
}
有人可以告诉我我做错了什么吗?感谢您的帮助。
innerJoin
方法调用中缺少参数。你必须这样做:
$shippingPriceReccords
= $this->em->createQueryBuilder()
->select('price')
->from('OrderShippingPrice', 'price')
->innerJoin('OrderShippingMethod', 'method', 'WITH', 'price.fkOrderShippingMethod = method.id')
->innerJoin('OrderShippingMethodRegionMapping', 'map', 'WITH', 'map.fkOrderShippingMethod = method.id')
->where('price.fkProductType = :fkProductType')
->andwhere('price.fkBrand = :fkBrand')
->andwhere('map.fkRegion = :fkRegion')
->setParameters([
'fkProductType' => $fkProductType,
'fkBrand' => $fkBrand,
'fkRegion' => $regionID,
])
->getQuery()
->setFetchMode("OrderCart", "address", DoctrineORMMappingClassMetadata::FETCH_EAGER)
->getResult();
请参阅文档:
// Example - $qb->innerJoin('u.Group', 'g', ExprJoin::WITH, $qb->expr()->eq('u.status_id', '?1'))
// Example - $qb->innerJoin('u.Group', 'g', 'WITH', 'u.status = ?1')
// Example - $qb->innerJoin('u.Group', 'g', 'WITH', 'u.status = ?1', 'g.id')
public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null);