1

I am using Symfony3 framework, and I have user entity, and file entity. I wanted to present in sonata administration user list with sum of all size files which are uploaded by user. When I want to make that field sortable I am getting error:

`Catchable Fatal Error: Argument 1 passed to Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery::entityJoin() must be of the type array, null given, called in /home/milos/sites/coinaphoto/vendor/sonata-project/doctrine-orm-admin-bundle/Datagrid/ProxyQuery.php on line 143 and defined`

I have custom function in User entity which is calculating sum of files. It returns string.

My question will be can I somehow pass dql to criteria in order to get sum. Or can you suggest some other way to implement this?

`    public function getStoragge(){
         $criteria = Criteria::create()
            ->where(Criteria::expr()->someexpression...);
         $matches = $this->file->matching($criteria);
     }`

Something similar like when you need to aggregate fields

`    $dql = "SELECT SUM(e.amount) AS balance FROM Bank\Entities\Entry e " .
     "WHERE e.account = ?1";
    $balance = $em->createQuery($dql)
              ->setParameter(1, $myAccountId)
              ->getSingleScalarResult();`
Milos Ilic
  • 23
  • 4

1 Answers1

0

I don't know about your dql thing, but some fact about sorting in Sonata Admin table views. The problem is, that sorting actions still be made in the background with database operations, no matter what you are doing "virtual" in your model. If you are adding just a method to your model, the datagrid is not able to involve this method/property in sorting.

My experience is, that you can't sort by fields which are not physically available in the corresponding table. Even if you write the whole query for yourself, if you click on the sort buttons, a complete other query is fired which is ignoring your request.

I'll be pleased if somebody tell me the contrary ...

See also this issue https://github.com/sonata-project/SonataAdminBundle/issues/1077

Jim Panse
  • 2,220
  • 12
  • 34
  • Yes I saw that issue, I just wanted to ask is somebody find solution or using some other method. – Milos Ilic Nov 02 '17 at 16:14
  • I just see a chance in rewriting the sorting behaviour ... i think thats just very deep core stuff (isn't it?) ... unfortunately i haven't found a way until now ... please tell me if theres a comfortable solution sometime ... – Jim Panse Nov 02 '17 at 16:17