php - Doctrine "Like" DQL -
i'm new doctrine , trying figure out dql query.
i have 2 entities country , venue.
country
<?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; } }
venue
<?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; } }
when execute query
select venue x\application\model\entity\venue venue venue.building '%fa%' or venue.street '%fa%' or venue.city '%fa%' or venue.contactnumber '%fa%' or venue.pointofcontact '%fa%' order venue.building asc
it works fine when add country(venue.country '%search%') in not work example
select venue x\application\model\entity\venue venue venue.building '%fa%' or venue.street '%fa%' or venue.city '%fa%' or venue.contactnumber '%fa%' or venue.pointofcontact '%fa%' venue.country '%fa%' order venue.building asc
can me on this, i'm sure in pure sql inner join how in doctrine. reading long question. :)
let me take opportunity answer own question. needed inner join. believe work same works in sql query.
inner join x\application\model\entity\country country venue.country = country.id
by adding part query after from work fine. final query looks like
select venue x\application\model\entity\venue venue inner join x\application\model\entity\country country venue.country = country.id venue.building '%united kingdom%' or venue.street '%united kingdom%' or venue.city '%united kingdom%' or venue.contactnumber '%united kingdom%' or venue.postcode '%united kingdom%' or venue.pointofcontact '%united kingdom%' or country.name '%united kingdom%' order venue.building asc
you can further read doctrine inner join here in querybuilder documentation
http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/query-builder.html
Comments
Post a Comment