开发者

Symfony custom form filters with a default table sort

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.

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:

public function addSeasonsListColumnQuery($q, $element, $value)
{
  if ($value)
  {
    $alias = $q->getRootAlias();
    $q
      ->innerJoin($alias . '.Drivers d')
      ->innerJoin('d.Seasons s')
      ->addWhere('s.id = ?', $value)
      -开发者_JAVA技巧>groupBy($alias . '.id');
    return $q;
  }
}

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:

public function __construct($name, Doctrine_Connection $conn, $initDefinition = false)
{
  parent::__construct($name, $conn, $initDefinition);
  $this->_options['orderBy'] = 'start_date DESC';
}

Which also works fine on its own (without the above). The problem comes with using both of these which gives me this error:

Column not found: 1054 Unknown column 's2.start_date' in 'order clause'

Query portion:

.. 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

The ordering by start_date has been applied to the linking table (seasons_drivers) too!?!

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.

Any ideas or suggestions ?

Thanks

Tom


I would try this:

public function addSeasonsListColumnQuery($q, $element, $value)
{
  if ($value)
  {
    $alias = $q->getRootAlias();
    $q
      ->innerJoin($alias . '.Drivers d')
      ->innerJoin('d.Seasons s')
      ->addWhere('s.id = ?', $value)
      ->groupBy($alias . '.id')
      ->orderBy('s.start_date DESC');
    return $q;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜