Yii v2 snippet guide II

Comparing #46 with #47

Revision #47 was created by rackycz rackycz on Oct 5, 2020, 8:20:23 PM.

Search sort related column

Content

[...]
// You must use joinWith() in order to have both tables in one JOIN - then you can call WHERE and ORDER BY on the 2nd table.
// Explanation here:
// https://stackoverflow.com/questions/25600048/what-is-the-difference-between-with-and-joinwith-in-yii2-and-when-to-use-them

$query = Invoice::find()->joinWith('company
Relation');

// Appending new sortable column:
$sort = $dataProvider->getSort();
$sort->attributes['company_name'] = [
'asc' => ['table.column' => SORT_ASC],
[...]