B
B
BonBon Slick2018-03-04 13:53:04
Doctrine ORM
BonBon Slick, 2018-03-04 13:53:04

How to filter data by links?

There is a sample, for example, select posts where User ID = 1.
Which approach is more correct:

->where('post.user = :user')
->setParameter('user', User $user) // принимаем класс
//or
->where('post.userId = :userId')
->setParameter('userId', (int) 1) // принимаем ID, только простые типы.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
novrm, 2018-03-04
@BonBonSlick

The correct second option.
For in the URL parameters you can only pass the id of the object, and not the object itself.

D
D3lphi, 2018-03-04
@D3lphi

The first option is more correct. ORM should work with objects, not with identifiers, it is O bject RM .
The fact that an entity has an identifier is the business of the entity itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question