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:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#binding-parameters-to-your-query


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -