I built up a plugin and inside the plugin I created the relation between Entry and Section using ActiveRecord, like below:
In SectionRecord :
class SectionRecord extends ActiveRecord
{
public static function tableName()
{
return '{{sections}}';
}
public function getEntries()
{
return $this->hasMany(EntryRecord::className(),['id' => 'sectionId']);
}
}
In EntryRecord file:
class EntryRecord extends ActiveRecord
{
public static function tableName()
{
return '{{entries}}';
}
public function getSection()
{
return $this->hasOne(SectionRecord::className(),['sectionId' => 'id']);
}
}
At last in controller:
$hub = SectionRecord::findOne(['handle'=>'hub']);
dd($hub->entries);
I tried to get section which is working, but when I wanna fetch entries under that section, showed me an error:
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: raintestplugin\test\records\SectionRecord::sectionId