PHPackages                             codiverum/yii2-relation-search-filter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. codiverum/yii2-relation-search-filter

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

codiverum/yii2-relation-search-filter
=====================================

Simple extension for making searching and filtering by related field simple.

1.0.7(10y ago)54383[1 issues](https://github.com/codiverum/yii2-relation-search-filter/issues)BSD-4-ClausePHP

Since Sep 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/codiverum/yii2-relation-search-filter)[ Packagist](https://packagist.org/packages/codiverum/yii2-relation-search-filter)[ RSS](/packages/codiverum-yii2-relation-search-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

Relation Search and Filtering
=============================

[](#relation-search-and-filtering)

Simple extension for making searching and filtering by related field simple.

Use this trait to easily add ability to display/filter by related entity attribute. It also allows to use table aliases. Extension is pretty simple but makes the code cleaner, especially when using aliases (there are some auto-formatting bugs in some IDEs).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist codiverum/yii2-relation-search-filter "*"

```

or add

```
"codiverum/yii2-relation-search-filter": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

To use the trait you need to do the following (first example without using aliases):

1. In top of your class (search-model) body put:

```
use \codiverum\relationSF\RelationSFTrait;

```

2. Make new public attribute in your class:

```
public $relation_name;

```

3. Add your attribute to safe attributes
4. In your search function add following:

- after creating $query add:

```
$this->joinWithRelation($query, 'relation_name');

```

- after creating $dataProvider add:

```
$this->addRelationSort($dataProvider, 'relation_name', 'related_table_field_name', 'table_name');

```

- after creating query filters add:

```
$this->addRelationFilter($query, 'relation_name', 'related_table_field_name', 'table_name');

```

5. Add to GridView columns array:

```
[
  'attribute' => 'relation_name',
  'value' => 'relation_name.related_table_field_name',
],

```

That's it.

Advanced Usage (with table aliases)
-----------------------------------

[](#advanced-usage-with-table-aliases)

1. In top of your class (search-model) body put:

```
use \codiverum\relationSF\RelationSFTrait;

```

2. Make new public attribute in your class:

```
public $relation_name;

```

3. Add your attribute to safe attributes
4. In your search function add following:

- after creating $query add:

```
$this->joinWithRelation($query, 'relation_name', 'table_name', 'alias');

```

- after creating $dataProvider add:

```
$this->addRelationSort($dataProvider, 'relation_name', 'related_table_field_name', 'alias');

```

- after creating query filters add:

```
$this->addRelationFilter($query, 'relation_name', 'related_table_field_name', 'alias');

```

5. Add to GridView columns array:

```
[
  'attribute' => 'relation_name',
  'value' => 'relation_name.related_table_field_name',
],

That's it.

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity68

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

8

Last Release

3857d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b012aeb934161c53376d587e74c8436ce5b90ff45bd85ad87014f96cceb6b99?d=identicon)[codiverum](/maintainers/codiverum)

---

Tags

searchfilteryii2extensionactive-recordrelation

### Embed Badge

![Health badge](/badges/codiverum-yii2-relation-search-filter/health.svg)

```
[![Health](https://phpackages.com/badges/codiverum-yii2-relation-search-filter/health.svg)](https://phpackages.com/packages/codiverum-yii2-relation-search-filter)
```

###  Alternatives

[vintage/yii2-search

Search in Active Record models for Yii2

294.6k](/packages/vintage-yii2-search)[thrieu/yii2-grid-view-state

Save filters from GridView to session, keep the filter state between pages.

1313.1k1](/packages/thrieu-yii2-grid-view-state)[vxm/yii2-searchable

Simple full-text search for Yii2 active record

181.4k](/packages/vxm-yii2-searchable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
