Hi all. Been here trying to get to grips with Yii for a project I am working on. Basically I am getting an unknown property error after adding a relation to a model, to pull data from another table. Spent all day trying to find answer to this and finally am asking for help…
I have a model Termclassstudent (model for a join table) which i am displaying on an input table for the parent student table.
I created relations in the Termclassstudent model to link back to related tables. When I add the final relation (with the data I want to display), and add the joinwith to my query in the view - i get the following error.
Getting unknown property: app\models\Termclassstudent::classid
model below
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "termclassstudent".
*
* @property integer $id
* @property integer $termclassid
* @property integer $studentid
*
* @property Termclass $termclass
* @property Student $student
*/
class Termclassstudent extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'termclassstudent';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['termclassid', 'studentid'], 'integer']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'termclassid' => 'Termclassid',
'studentid' => 'Studentid',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTermclass()
{
return $this->hasOne(Termclass::className(), ['id' => 'termclassid']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStudent()
{
return $this->hasOne(Student::className(), ['id' => 'studentid']);
}
public function getClasse()
{
return $this->hasOne(Classe::className(), ['id' => 'classid'])
->via('termclass');
}
public function getClassday()
{
return $this->hasone(Classday::className(), ['id' => 'dayid'])
->via('classe');
}
}
and the offending view code :
<div class="student-form">
<?php $form = ActiveForm::begin(); ?>
<?php if (!$model->isNewRecord):?>
<h2> Classes </h2>
<?= \yii\grid\GridView::widget([
'dataProvider' => new \yii\data\ActiveDataProvider ([
'query' => $model->getTermclassstudents()->joinWith('termclass')->joinWith('classe')->joinWith('classday'),
'pagination' => false
]),
'columns' => ['classday.name','classe.name','classe.time',
[
'class' => \yii\grid\ActionColumn::className(),
'controller' => 'termclassstudent',
'header' => Html::a('<i class="glyphicon glyphicon-plus"></i> Add New', ['termclassstudent/create','relation_id'=>$model->id]),
]
]
]);
?>
<?php endif?>
it all works till I add the final joinWith(‘classday’) to my query. classid, which the error refers to is in the Termclass model.
I can’t see what is wrong, retyped, regenerated etc etc. I could be missing something obvious or misunderstanding how the relation functions, but what??