In a project I am working on at the moment is not finding the part number in the database its using symfony 2.7 and doctrine. Ive tried find, findBy, findOneBy, and findAll still none of them is able to find the correct part number that is in the database.
This is supposed to search the database and find like part numbers and display it on the page. Going through to process is as follows.
1.The user uploads an invoice by copying and pasting from an excel file using the Site form
Then the information is grabbed and the items are put placed into an array.
if ($import) { $importData = $form->get('importData')->getData(); /* @var $invoice OnWaterInvoice */ $pattern = '/"(.+)\r\n?(.+)"/'; $replace = '$1$2'; $importData = preg_replace($pattern, $replace, $importData); $importData = explode("\r\n", $importData); foreach ($importData as $item) { $item = trim($item); $item = explode("\t", $item); foreach ($item as $key => $value) { $value = trim($value); if ($key == 0 || $key == 4) { $value = (int) $value; } if ($key == 5 || $key == 6) { $value = (float) $value; } $item[$key] = $value; }This is where I am having issue is this line of code right here
$pn = $this->getDoctrine()->getRepository('EICStockBundle:PartNumber')->find($item[2]); $invoiceItem->setPartNumber($pn);
This doesn't grab the part number even though it is in the database. Its as though the values aren't updating. Because if a new number is added I get the same result. It skips it.
the part number is the id of the table however when I use
->findBy('id'=>$item[2]) I get an error.
This is supposed to find the part as well as possible parts because sometimes the incorrect part number is used. If I could get some pointers on what I am doing wrong I would greatly appreciate it.
Thank you
UPDATE ----
Ive tried clearing the doctrine cache using
doctrine:cache:clear-collection-region doctrine:cache:clear-entity-region doctrine:cache:clear-metadata
I've also tried to schema:rebuild and Update but still hasn't pull the correct id
You are trying to find a database entry via ID, which is in this case a float number and in other cases an integer. I think (and strongly recommend) that your ID is not a float but an integer. So this could be the potential problem - both for doctrine and for MySQL.
What error are you getting, if you use the following?
Another potential problem could be the following line. Here you are overwriting the looped array:
Is this done on purpose?
Have you done a
var_dump($item)before you are executing thefind()method to see if the values are correctly?PS: Are you using Symfony 2.7 for a specific reason? Symfony 5.4 is the LTS now, so we are 3 major version ahead right now.