OctoberCMS, How To Define Relationship With Children Model?
I need render children model in template, my parent model "Form" haves db field "field_id", where field_id equals id children model "Field". How can I access the child model? I tried add relation to Field model:
public $hasOne = [ 'field' => ['\Webfather\Services\Models\Variation', 'key' => 'field_id'] ];
and tried display in template:
but form.field was empty
your relation linking is wrong.
what you need to do is, you need to define
form_id inside your child model(
you need to insert form_id => 'parent model (
Form) id' there
public $hasOne = [ 'field' => ['\Webfather\Services\Models\Variation', 'key' => 'form_id'] ];
so now it will search child model(
id of parent
and then you can get child record.
OR to make it working with current scenario you need to make
Form model as child. (less code changes)
public $belongsTo = [ 'field' => ['\Webfather\Services\Models\Variation', 'key' => 'field_id'] ];
now you can use
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?