【发布时间】:2016-05-28 10:53:18
【问题描述】:
我是 Doctrine 的新手,想弄清楚 DQL 查询。
我有 2 个实体国家和地点。
国家
<?php
namespace X\application\model\entity;
/** @Entity */
class country
{
/**
* @Id
* @Column(type="string",length=2)
* @GeneratedValue(strategy="NONE")
*/
protected $id;
/** @Column(type="string",length=255,nullable=false) */
protected $name;
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
}
场地
<?php
namespace X\application\model\entity;
/** @Entity */
class venue
{
/**
* @var \Ramsey\Uuid\Uuid
*
* @Id
* @Column(type="uuid")
* @GeneratedValue(strategy="NONE")
*/
protected $id;
/** @Column(type="string",length=255,nullable=true) */
protected $building;
/** @Column(type="string",length=255,nullable=false) */
protected $street;
/** @Column(type="string",length=255,nullable=false) */
protected $city;
/** @Column(type="string",name="post_code",length=255,nullable=true) */
protected $postCode;
/** @Column(type="string",name="contact_number",length=255,nullable=true) */
protected $contactNumber;
/** @Column(type="text",name="point_of_contact",length=20000,nullable=true) */
protected $pointOfContact;
/** @Column(type="text",length=20000,nullable=true) */
protected $note;
/**
* @ManyToOne(targetEntity="country", inversedBy="id")
**/
protected $country;
/**
* venue constructor.
* @param $building
* @param $street
* @param $city
* @param $postCode
* @param $contactNumber
* @param $pointOfContact
* @param $note
* @param $country
*/
public function __construct($building, $street, $city, $postCode, $contactNumber, $pointOfContact, $note, $country)
{
$this->id = \Ramsey\Uuid\Uuid::uuid4();
$this->building = $building;
$this->street = $street;
$this->city = $city;
$this->postCode = $postCode;
$this->contactNumber = $contactNumber;
$this->pointOfContact = $pointOfContact;
$this->note = $note;
$this->country = $country;
}
/**
* @return \Ramsey\Uuid\Uuid
*/
public function getId()
{
return $this->id;
}
/**
* @param \Ramsey\Uuid\Uuid $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getBuilding()
{
return $this->building;
}
/**
* @param mixed $building
*/
public function setBuilding($building)
{
$this->building = $building;
}
/**
* @return mixed
*/
public function getStreet()
{
return $this->street;
}
/**
* @param mixed $street
*/
public function setStreet($street)
{
$this->street = $street;
}
/**
* @return mixed
*/
public function getCity()
{
return $this->city;
}
/**
* @param mixed $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* @return mixed
*/
public function getPostCode()
{
return $this->postCode;
}
/**
* @param mixed $postCode
*/
public function setPostCode($postCode)
{
$this->postCode = $postCode;
}
/**
* @return mixed
*/
public function getContactNumber()
{
return $this->contactNumber;
}
/**
* @param mixed $contactNumber
*/
public function setContactNumber($contactNumber)
{
$this->contactNumber = $contactNumber;
}
/**
* @return mixed
*/
public function getPointOfContact()
{
return $this->pointOfContact;
}
/**
* @param mixed $pointOfContact
*/
public function setPointOfContact($pointOfContact)
{
$this->pointOfContact = $pointOfContact;
}
/**
* @return mixed
*/
public function getNote()
{
return $this->note;
}
/**
* @param mixed $note
*/
public function setNote($note)
{
$this->note = $note;
}
/**
* @return country | null
*/
public function getCountry()
{
return $this->country;
}
/**
* @param mixed $country
*/
public function setCountry($country)
{
$this->country = $country;
}
}
当我执行这个查询时
SELECT venue FROM X\application\model\entity\venue venue WHERE venue.building
LIKE '%fa%' OR venue.street LIKE '%fa%' OR venue.city LIKE '%fa%' OR
venue.contactNumber LIKE '%fa%' OR venue.pointOfContact LIKE '%fa%' ORDER BY
venue.building ASC
它工作得很好,但是当我添加国家(venue.country LIKE '%search%')时,例如它不起作用
SELECT venue FROM X\application\model\entity\venue venue WHERE venue.building
LIKE '%fa%' OR venue.street LIKE '%fa%' OR venue.city LIKE '%fa%' OR
venue.contactNumber LIKE '%fa%' OR venue.pointOfContact LIKE '%fa%'
venue.country LIKE '%fa%' ORDER BY venue.building ASC
任何人都可以帮我解决这个问题,我确信在纯 SQL 中你会进行内部连接,但你在 Doctrine 中的表现如何。感谢您阅读长问题。 :)
【问题讨论】:
标签: php sql orm doctrine-orm doctrine