doctrine2 - Doctrine - QueryBuilder, select query with where parameters: entities or ids? -
i have product entity , shop entity.
a shop can have 0 n products , product can in 1 shop.
the product entity table refering shop entity through shop_id table field.
when querying products of given shop using doctrine query builder, can this:
$products = $this->getdoctrine()->getrepository('mybundle:product') ->createquerybuilder('p') ->where('p.shop = :shop') ->setparameter('shop', $shop) // here pass shop object ->getquery()->getresult();
or this:
$products = $this->getdoctrine()->getrepository('mybundle:product') ->createquerybuilder('p') ->where('p.shop = :shopid') ->setparameter('shopid', $shopid) // pass directly shop id ->getquery()->getresult();
and both seem work... i'm wondering: can pass directly entity ids instead of entity instances in such cases (ie: on doctrine entity field refers entity)?
i thought first example work...
according doctrine documentation, can pass object setparameter()
if object managed.
extract documentation:
calling setparameter() automatically infers type setting value. works integers, arrays of strings/integers, datetime instances and managed entities.
for more information, please see:
Comments
Post a Comment