In which widget are you trying to show related model value?
If in view file, then I guess it is DetailView widget.
What is relation between Student and Category model? Again, just guessing relation between your Student and Category models is (Many student will by in one category).
Thanks, your suggestion worked. but I had to modify the relation method generated by gii.
Generated Method.
public function getCategories()
{
return $this->hasOne SmartCategories::className(), ['id' => 'categories_id']);
}
Modified Method
public function getCategories()
{
return $this->hasOne Categories::className(), ['id' => 'categories_id']);
}
Can anyone explain what should actually go in there in this code and why gii generated the code like SmartCategories, which didn’t worked. My underlying table name is smart_categories.
is giving table prefix creating more confusion here?
Gii tries to define the relation’s class name from that of the underlying table. When you have set the class name for ‘smart_categories’ table as ‘Categories’ manually, then you have to modify the code generated by Gii manually.
Things are much more easier for you when you follow the naming conventions of Yii.