0

I'm trying to order a list of entity according to who's logged in and based on the last action done.

For example, i'm logged in as admin A, and in a list of people, i'm doing something in the profile of User C.

The output i need is:

  • for admin A: people ordered like this : C - A - B - D -E ...
  • for other admins: people ordered like this : A - B - C - D ...

To do so i did a table looking with these attribute:

  • id : auto - generated
  • adminId
  • userId
  • DateOfLastAction

With a link OneToMany (one user -> many order) between the 2 tables (mappedBy : userId, inversed by iD) because a given user can have different "DateOfLastAction" according to the adminID who did the action.

Problem now is when i want to order my user by DateOfLastAction, i can't be done because of the OneToMany relationship..

(doing like the given answer in this post)

So the best would be to transform it to a *ToOne realtionship. Would a composite primary key help me? Does someone have any idea of a better design?

Lilian Barraud
  • 337
  • 1
  • 11
  • Have you try to add a left join to your 'peoples' query with your new table, then order by DateOfLastAction and order by id? – Charlie Lucas Apr 18 '18 at 09:35
  • I tried what you said and..It won't let me.. in Sonata, in your admin, you can modify the query by overwritting the `createQuery` method, though you can't choose the selected field. Also, it won't let me set an `OrderBy` on unselected field. So i did the leftJoin, but it won't let me `orderBy('DateOfLastAction','DESC')` directly in the query – Lilian Barraud Apr 18 '18 at 13:20
  • If you can overwrite the query, you have a possibility to do it, proceed by steps. I think you are missing the alias for your order by, can you copy the query? – Charlie Lucas Apr 19 '18 at 14:19

0 Answers0