PHPackages                             grinat/yii2-union-data-provider - 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. grinat/yii2-union-data-provider

ActiveYii2-extension

grinat/yii2-union-data-provider
===============================

Data provider which joins different tables via union

2771PHP

Since Nov 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/grinat/yii2-union-data-provider)[ Packagist](https://packagist.org/packages/grinat/yii2-union-data-provider)[ RSS](/packages/grinat-yii2-union-data-provider/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist grinat/yii2-union-data-provider

```

or add

```
"grinat/yii2-union-data-provider": "^0.1.0"

```

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

or

```
php /usr/bin/composer require --prefer-dist grinat/yii2-union-data-provider

```

or

```
php your_composer_path require --prefer-dist grinat/yii2-union-data-provider

```

Usage
-----

[](#usage)

```
use grinat\uniondataprovider\UnionDataProvider;
use yii\base\Model;

class ListOfActivityUnionModel extends Model{

    public function search()
    {
        $dataProvider = new UnionDataProvider([
            // model which attributes use for sort data
            'searchModel' => $this,
            'options' => [
                // needed fields
                'select' => 'id,comment,created_at,user_id',
                'union' => [
                    [
                         // set in class path to model
                        'class' => 'app\modules\recipe\models\RecipeComment',
                        // aliases for fields which have diiferent name
                        // was return in that example as relationColumn
                        // if the names are the same, specify them in select
                        'selectAs' => ['recipe_id' => 'relationColumn'],
                        // set relation of you need corresponds to $query->width('createdUser')
                        // if in relation used column with alias, set it as [alias => relationName]
                        'withRel' => ['createdUser', 'relationColumn' => 'recipe']
                    ],
                    [
                        'class' => 'app\modules\coach\models\CoachDietReview',
                        'selectAs' => ['diet_id' => 'relationColumn'],
                        'withRel' => ['createdUser', 'relationColumn' => 'diet']
                    ],
                    [
                        'class' => 'app\modules\coach\models\CoachReview',
                        'selectAs' => ['coach_id' => 'relationColumn'],
                        'withRel' => ['createdUser', 'relationColumn' => 'coach.createdUser']
                    ]
                ]
            ],
            'sort' => [
                'defaultOrder' => ['created_at' => SORT_DESC],
            ],
            // string Set null if need primaryKey for relWith from data scheme
            // 'unionRelsPk' => 'id',
            // Return data from provider As array or not
            // 'asArray' => false,
            // Set false if dont need duplicates
            // 'unionAll' => false,
            // if needed correct data-key in GrigView and etc
            // 'key' => 'id'
        ]);

        return $dataProvider;
    }
}

```

The execute query is:

```
SELECT *
FROM   ((SELECT "id",
                "comment",
                "created_at",
                "user_id",
                Concat('0') AS union_index,
                "recipe_id" AS "relationColumn"
         FROM   "recipe_comment")
        UNION ALL
        (SELECT "id",
                "comment",
                "created_at",
                "user_id",
                Concat('1') AS union_index,
                "diet_id"   AS "relationColumn"
         FROM   "coach_diet_review")
        UNION ALL
        (SELECT "id",
                "comment",
                "created_at",
                "user_id",
                Concat('2') AS union_index,
                "coach_id"  AS "relationColumn"
         FROM   "coach_review")) "dummy_table"
ORDER  BY "created_at" DESC
LIMIT  10

```

With queries

```
SELECT * FROM "user" WHERE "id" IN (5, 13, 3)
SELECT * FROM "recipe_recipe" WHERE "id" IN (1, 2, 18, 9)
...etc
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/43cf04d05a7941f5f598868c9eaafd0301b0cbaa6a0d531492e071c5fc52796d?d=identicon)[grinat](/maintainers/grinat)

---

Top Contributors

[![grinat](https://avatars.githubusercontent.com/u/16123366?v=4)](https://github.com/grinat "grinat (4 commits)")[![Baha2Odeh](https://avatars.githubusercontent.com/u/2823958?v=4)](https://github.com/Baha2Odeh "Baha2Odeh (1 commits)")

### Embed Badge

![Health badge](/badges/grinat-yii2-union-data-provider/health.svg)

```
[![Health](https://phpackages.com/badges/grinat-yii2-union-data-provider/health.svg)](https://phpackages.com/packages/grinat-yii2-union-data-provider)
```

PHPackages © 2026

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