Sunday 15 March 2015

php - How do I search by properties of entity which do not have @Column anotation in Doctrine2? -



php - How do I search by properties of entity which do not have @Column anotation in Doctrine2? -

/** * @orm\entity */ class order extends baseentity { // trait @id utilize identifier; /** * @orm\column(type="integer") */ protected $costperunit; /** * @orm\column(type="integer") */ protected $numberofunits; // want search property protected $totalcost; public function gettotalcost() { homecoming $this->numberofunits * $this->costperunit; } }

i have entity , i'd able example

$orderrepository->findonebytotalcost('999') $orderrepository->findby(['totalcost' => '400']);

is possible in doctrine2? or go differently?

you should write method findonebytotalcost on entity repository, like:

public function findonebytotalcost ($queryparams){ $query = 'select o <yourentity> o o.numberofunits * o.costperunit = :myparam'; $dql = $this->getentitymanager()->createquery($query); $dql->setparameter('myparam', $queryparams); homecoming $dql ->execute(); }

them, $orderrepository->findonebytotalcost('999') should work.

php orm doctrine2 doctrine entity

No comments:

Post a Comment