I am very new to the Doctrine, so this may seem like a pretty obvious question for those more experienced.
I am writing a data import tool that should verify that each imported row contains valid data. For example, the line contains a link to the product code, I need to check if an existing Product object exists with this code. If not, mark this line as invalid.
Now I can easily do something similar for each row.
$productCode = $this->csv->getProductNumber(); $product = $doctrine->getRepository('MyBundle:Product')->findOneBy(array('code' => $productCode ));
But that seems terribly ineffective. So I thought about returning the entire product collection, and then iterating through it.
$query = $this->getEntityManager()->createQuery('SELECT p FROM MyBundle\Entity\Product p'); $products = $query->getResult();
All is well and good, but then I need to write messy loops for the search.
Two questions:
1). I was wondering if I lacked some useful methods, for example, in your Magento Collections, where you can search the Collection results without additional database deletions. For example, in Magento, this will iterate over the collection and filter by code property.
$collection->getItemByColumnValue("code","FZTY444");
2). At the moment, I am using the query below, which returns a "rectangular array". More effective, but could be better.
$query = $this->getEntityManager()->createQuery('SELECT p.code FROM MyBundle\Entity\Product p'); $products = $query->getResult();
Is there a way to return a single dimensional array without repeating the result set and converting it to a flat array, so I can use in_array () for the results?