R
R
rabadan7312016-02-07 15:00:15
Yii
rabadan731, 2016-02-07 15:00:15

How to make connection in yii2 many-to-many with negative condition?

There are three tables: firms, categories and a table with the category belonging to the firm: firm_category.
To get all categories of our company, I use the following many-to-many relationship:

public function getCategories()
    {
        return $this->hasMany(Category::className(), ['id' => 'category_id'])
            ->viaTable('company_category', ['company_id' => 'id']);
    }

Is it possible to build such a many-to-many relationship where you get non -company categories?
What is the correct way to implement such a task?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2016-02-07
@kentuck1213

try inserting !

A
Anton Natarov, 2016-02-08
@HanDroid

1. Get what belongs to your firm.
2. Get all categories.
3. Subtract from from the total osprey belonging to.
4. The rest show where you need.
5. Wrap all requests in a transaction. And pre-index the fields by which you select. The base will thank you =)
Perhaps there is a more capacious solution, but this is from the category of the obvious.

R
rabadan731, 2016-02-08
@rabadan731

Anton Natarov , I usually used this option.
I thought maybe you can do it somehow "beautifully" by means of links specified in the framework. So I decided to ask here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question