1
votes

I have 2 tables:

  "article":
|id|name|text|

  "article_permissions"
|article_id|val|

So, I wan't to join article_permissions to Article::find()->all(); (and filter by article_permissions::val).

I've tried to do like this:

Article::find()->with('articlePermissions')->all()

And function in ArticleModel (generated by gii):

public function getArticlePermissions()
{
    return $this->hasOne(ArticlePermissions::className(), ['article_id' => 'id']);
}

but it returns:

The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses. :(

What am I doing wrong?

1
you are defining the relation with getArticleCategory but you are accessing it with articlePermissions. Also getArticleCategory would not get created by gii from articlePermissions... you are showing the wrong code. - Mihai P.
@MihaiP. you're right. I've renamed variables in post, but I've forget to rename a function. Anyway, I have found an answer, just removing "->all();" - Alexey Berezuev

1 Answers

0
votes

The answers is to change this:

Article::find()->with('articlePermissions')->all();

TO that: Article::find()->with('articlePermissions');