How about retrieving all the current titles into an array first and checking the inserting title against the current titles in that array $existingTitles = $em->getRepository('ListItem')->getCurrentTitles(); foreach($json->value->items as $item) { if (!in_array($item->title, $existingTitles)) { $listItem = new ListItem(); $listItem->setTitle($item->title); $em->persist($listItem); } } $em->flush() getCurrentTitles() would need to be added to ListItem Repo to simply return an array of titles This only requires one extra DB query but does cost you more in memory to hold the current titles in an array. There maybe problems with this method if your dataset for ListItem is very big If the number of items your want to insert each time isn't too large, you could modify the getCurrentTitles() function to query for all those items with the titles your trying to insert. This way the max amount of $existingTiles you will return will be the size of your insert data list.
Then you could perform your checks as above getCurrentTitles() - $newTitles is array of all new titles you want to insert return $qb->select('title') ->from('Table', 't') ->in('t. Title = ', $newTitles) ->getArrayResult().
How about retrieving all the current titles into an array first and checking the inserting title against the current titles in that array $existingTitles = $em->getRepository('ListItem')->getCurrentTitles(); foreach($json->value->items as $item) { if (!in_array($item->title, $existingTitles)) { $listItem = new ListItem(); $listItem->setTitle($item->title); $em->persist($listItem); } } $em->flush(); getCurrentTitles() would need to be added to ListItem Repo to simply return an array of titles. This only requires one extra DB query but does cost you more in memory to hold the current titles in an array. There maybe problems with this method if your dataset for ListItem is very big.
If the number of items your want to insert each time isn't too large, you could modify the getCurrentTitles() function to query for all those items with the titles your trying to insert. This way the max amount of $existingTiles you will return will be the size of your insert data list. Then you could perform your checks as above.
// getCurrentTitles() - $newTitles is array of all new titles you want to insert return $qb->select('title') ->from('Table', 't') ->in('t. Title = ', $newTitles) ->getArrayResult().
Yes, it is indeed very big. Isn't there a way to do this on the database side? – choise Apr 20 at 19:29 How many items are you adding via AJAX at a time, is this a lot aswell?
– d.syph.3r Apr 21 at 6:59 There is a replace() method available in Doctrine 1, but I cannot seem to find any equivilant in Doctrine 2. – d.syph.3r Apr 21 at 7:57.
If you are using an entity that may already exists in the manager you have to merge it. Here is what I would do (did not test it yet) : $repository = $this->get('doctrine.orm. Entity_manager'); foreach($json->value->items as $item) { $listItem = new ListItem(); $listItem->setTitle($item->title); $em->merge($listItem); // return a managed entity // no need to persist as long as the entity is now managed } $em->flush().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.