Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony custom form filters with a default table sort
    text
    copied!<p>I have a set up like this: Drivers, Seasons, Teams. Drivers are many-many with Teams and many-many with Seasons. Note there is no direct link from Teams to Seasons.</p> <p>I have a filter form for Teams. I want a Season select widget so I can filter to Teams which have Drivers who are associated with selected Season. I have added this query code in TeamFormFilter.class:</p> <pre><code>public function addSeasonsListColumnQuery($q, $element, $value) { if ($value) { $alias = $q-&gt;getRootAlias(); $q -&gt;innerJoin($alias . '.Drivers d') -&gt;innerJoin('d.Seasons s') -&gt;addWhere('s.id = ?', $value) -&gt;groupBy($alias . '.id'); return $q; } } </code></pre> <p>This works fine on its own (without the below). I also have a default sort-order set up on the Seasons table (in SeasonTable.class) using this method:</p> <pre><code>public function __construct($name, Doctrine_Connection $conn, $initDefinition = false) { parent::__construct($name, $conn, $initDefinition); $this-&gt;_options['orderBy'] = 'start_date DESC'; } </code></pre> <p>Which also works fine on its own (without the above). The problem comes with using both of these which gives me this error: </p> <pre><code>Column not found: 1054 Unknown column 's2.start_date' in 'order clause' </code></pre> <p>Query portion:</p> <pre><code>.. FROM teams t INNER JOIN drivers d ON t.id = d.team_id AND (d.deleted_at IS NULL) INNER JOIN seasons_drivers s2 ON (d.id = s2.driver_id) INNER JOIN seasons s ON s.id = s2.season_id .... ORDER BY t.name ASC, d.driver_number ASC, s.start_date DESC, s2.start_date DESC </code></pre> <p>The ordering by start_date has been applied to the linking table (seasons_drivers) too!?!</p> <p>After hours of digging into the codebase, I conclude that either a) this is a doctrine bug or b) fundamentally I cant use the default order on a table in the way I have.</p> <p>Any ideas or suggestions ? </p> <p>Thanks</p> <p>Tom</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload