I went from 5.x to 7.x, so I am completely lost when it comes to using the ORM to find records at this point. I spent years writing queries like this:
I know I need to use dependency injection and the query builder. However, nothing I've tried has worked. I initially became confused when findOne wasn't working the way I expected, which led me to realize there are massive differences in the ORM compared to what I am used to. If someone could please help me build a simple query, maybe that will be enough to get me going in the right direction.
This is what I've been trying to do:
I think I need to do something like this:
I have no idea if that is correct because I can't get it to work. Also, I don't know what to do with it even if that is the right syntax. The examples show many more statements; this used to be a one-liner, so I must be missing something.
PHP Code:
$this->getEntityManager()->getRepository('Project')->where(array('value' => 10))->find(array('name','value'));
This is what I've been trying to do:
PHP Code:
52 $expense = $this->entityManager->getRDBRepository('Expenses')->where(array(
53 'date' => $pDate->format('Y-m-d'),
54 'amount' => $amount,
55 'description' => $description,
56 ))->findOne(['name','amount','date']]);
PHP Code:
$selectQuery = $this->entityManager->getQueryBuilder()->where(array(
'date' => $pDate->format('Y-m-d'),
'amount' => $amount,
'description' => $description,
))->select(['name','amount','date'])->build();
Comment