symfony - How to get not find multiple values in doctrine -


if search entities array in doctrine like:

$names = ['jim', 'anne', 'kara']; $em->findbyname($names); 

how can know then, names not found? of course, can loop returned array , check each name again. maybe there doctrine method returns not found names?

as far know, can't achieve using entityrepository apis, use array_diff , array_map together, single line solution, follow:

$names = ['jim', 'anne', 'kara']; $res = $em->getrepository('yourbundle:yourentity')->findbyname($names); $notfound = array_diff($names, array_map(function($obj){ return $obj->getname(); }, $res)); 

consider array_diff use === operator compare values, names must equal duplicates. if don't want take care lower/upper cases, convert strtolower.

$notfound = array_diff(array_map('strtolower', $names), array_map(function($obj){ return strtolower($obj->getname()); }, $res)); 

of course assumed have declared name getter in entity.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -