Answer the question
In order to leave comments, you need to log in
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']);
}
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question