Doctrine query builder using inner join with conditions

I’m going to answer my own question. innerJoin should use the keyword “WITH” instead of “ON” (Doctrine’s documentation [13.2.6. Helper methods] is inaccurate; [13.2.5. The Expr class] is correct) no need to link foreign keys in join condition as they’re already specified in the entity mapping. Therefore, the following works for me $qb->select(‘c’) ->innerJoin(‘c.phones’, ‘p’, … Read more

Doctrine 2.1 – datetime column default value

For default value CURRENT_TIMESTAMP: @ORM\Column(name=”created_at”, type=”datetime”, options={“default”: “CURRENT_TIMESTAMP”}) Or for older Symfony versions: @ORM\Column(name=”created_at”, type=”datetime”, options={“default”: 0}) Worked for me… However this works only with MySQL.

Symfony getting logged in user’s id

Current Symfony versions (Symfony 4, Symfony >=3.2) Since Symfony >=3.2 you can simply expect a UserInterface implementation to be injected to your controller action directly. You can then call getId() to retrieve user’s identifier: class DefaultController extends Controller { // when the user is mandatory (e.g. behind a firewall) public function fooAction(UserInterface $user) { $userId … Read more

How to limit size of result set in doctrine 2?

In Doctrine 2.1 method EntityRepository#findBy() now accepts additional parameters for ordering, limit and offset. Documentation: Working with objects – Querying by simple conditions Example: public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) usage: $myLimit = 30; $myOffset = 20; $product = $repository->findBy( array(‘name’ => ‘foo’), array(‘price’ => ‘ASC’), $myLimit, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)