M
M
Maxim2016-09-20 00:05:04
Yii
Maxim, 2016-09-20 00:05:04

Why doesn't relation work in yii2?

Tags.php

public function getArt() {
  $this->hasMany(Art::className(), ['id' => 'art_id'])
    ->viaTable('art_tag', ['tag_id' => 'id']);
}

controller
$tag = Tags::find()->joinWith('art')->where(['id' => $tag])->all();

As a result, the error
backend\models\Tags has no relation named "art".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-09-20
@1kachan

return

public function getArt() {
  return $this->hasMany(Art::className(), ['id' => 'art_id'])
    ->viaTable('art_tag', ['tag_id' => 'id']);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question