Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
examples:builder:hasone_relation [2021/03/26 21:36] pdsci-admin [The hasOne relation] |
examples:builder:hasone_relation [2021/03/27 07:54] (current) pdsci-admin [Step 5: Create the config_relation.yaml controller file] |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ====== The hasOne relation ====== | ====== The hasOne relation ====== | ||
| - | | + | |
| \\ | \\ | ||
| <WRAP tip> | <WRAP tip> | ||
| **Todo Cheat Sheet**\\ | **Todo Cheat Sheet**\\ | ||
| * Required: a // | * Required: a // | ||
| - | * Add a field named [parentModelName]_id **to the child table** | + | * Add a field named: //[parentModelName]_id// **to the child table** |
| * Create a model for the child table with list and form | * Create a model for the child table with list and form | ||
| * Extend **the parent controller** with relation behaviour | * Extend **the parent controller** with relation behaviour | ||
| - | * Extend **the parent model** with the desired relation (// | + | * Extend **the parent model** with the desired relation |
| - | * Define the details of how to handle the relation in the config_relation.yaml in the parent controller | + | * Define the details of how to handle the relation in the //config_relation.yaml// in the parent controller |
| * Use a //Partial// widget to include the child fields/ | * Use a //Partial// widget to include the child fields/ | ||
| </ | </ | ||
| - | In the example used here, the parent will be the book table, the child table is a descroption | + | In the library |
| ===== What it will look like ===== | ===== What it will look like ===== | ||
| This is what a record with an related record will look like in the example by adding a description to a book. In this example the related form was added into an extra tab on the book form with the options to create a new description, | This is what a record with an related record will look like in the example by adding a description to a book. In this example the related form was added into an extra tab on the book form with the options to create a new description, | ||
| Line 26: | Line 26: | ||
| * an installed [[https:// | * an installed [[https:// | ||
| * any source code editor or e.g. the [[https:// | * any source code editor or e.g. the [[https:// | ||
| - | * a database table for records to attach the media to | ||
| - | * a form (at least in backend) to display the media | ||
| - | * some media already uploaded to the media manager or ready to do so | ||
| Required skills\\ | Required skills\\ | ||
| Line 63: | Line 60: | ||
| {{: | {{: | ||
| <WRAP clear /> | <WRAP clear /> | ||
| + | \\ | ||
| + | \\ | ||
| + | Here is the complete code to copy, the highlighted rows are the lines probably to add, if the controller was already created. Please remember // | ||
| + | \\ | ||
| + | <sxh php; highlight: [10,18]> | ||
| + | <?php namespace Pds\Library\Controllers; | ||
| + | |||
| + | use Backend\Classes\Controller; | ||
| + | use BackendMenu; | ||
| + | |||
| + | class Books extends Controller | ||
| + | { | ||
| + | public $implement = [' | ||
| + | ' | ||
| + | ' | ||
| + | | ||
| + | public $listConfig = ' | ||
| + | public $formConfig = ' | ||
| + | | ||
| + | //add configuration of relation for Books | ||
| + | // this file has to be created then manually inside the | ||
| + | // [namespace]\controllers\[controllername] folder | ||
| + | public $relationConfig = ' | ||
| + | |||
| + | public function __construct() | ||
| + | { | ||
| + | parent:: | ||
| + | BackendMenu:: | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| \\ | \\ | ||
| ===== Step 3: Extend the parent controller ===== | ===== Step 3: Extend the parent controller ===== | ||
| Line 174: | Line 202: | ||
| <sxh yaml> | <sxh yaml> | ||
| + | ... | ||
| + | |||
| description: | description: | ||
| label: Description | label: Description | ||
| Line 182: | Line 212: | ||
| form: $/ | form: $/ | ||
| list: $/ | list: $/ | ||
| + | |||
| + | ... | ||
| </ | </ | ||