1

I am basically trying to execute dql as below:

$queryString = "SELECT ac FROM CloudExchange\Entities\Account ac JOIN ac.account_connections cn WHERE cn.account IN (:accounts)";
$query = $em->createQuery($queryString);
$query->setParameter('accounts', $service->getAccounts());
$results = $query->getResult();

I am using doctrine 2.3.x version. Seems like the above approach doesn't work. It returns following error:

PHP Catchable fatal error:  Object of class Doctrine\ORM\PersistentCollection could not be converted to string in......

Can anyone have any idea what is possibly wrong with my approach or what alternative better way to achieve "WHERE IN" condition based DQL please? Thanks.

2
  • 1
    Are you trying to echo a collection somewhere? Check the line it tells you, see if something is trying to be used as a string Commented Jun 27, 2014 at 3:11
  • Thanks for the clue. Actually, I need to make the collection to array as $service->getAccounts()->toArray() and it worked! Commented Jun 27, 2014 at 3:28

1 Answer 1

2

OK, just answering my own question, here is the proper way:

$queryString = "SELECT ac FROM CloudExchange\Entities\Account ac JOIN ac.account_connections cn WHERE cn.account IN (:accounts)";
$query = $em->createQuery($queryString);
$query->setParameter('accounts', $service->getAccounts()->toArray());
$results = $query->getResult();

So, basically I needed to use "$service->getAccounts()->toArray()", collection aren't supported directly inside DQL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.