examples:builder:hasone_relation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
examples:builder:hasone_relation [2021/03/26 21:44]
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 15: Line 15:
 </WRAP> </WRAP>
  
-In the library example used in this wiki, the **parent** will be the **book table**, the **child** table is a **descroption** table where a single description (a record) can be linked to exactly one book.+In the library example used in this wiki, the **parent** will be the **book table**, the **child** table is a **description** table where a single description (a record) can be linked to exactly one book.
 ===== 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, to edit or delete an existing 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, to edit or delete an existing description.\\
Line 26: Line 26:
   * an installed [[https://octobercms.com/plugin/rainlab-builder|builder plugin]]   * an installed [[https://octobercms.com/plugin/rainlab-builder|builder plugin]]
   * any source code editor or e.g. the [[https://octobercms.com/plugin/indikator-devtools|Developer Tools]] plugin with built-in Code editor like to be seen on the screenshoots   * any source code editor or e.g. the [[https://octobercms.com/plugin/indikator-devtools|Developer Tools]] plugin with built-in Code editor like to be seen on the screenshoots
-  * 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:
 {{:examples:builder:hasone-childmodel-form.jpg?direct&960 |}} {{:examples:builder:hasone-childmodel-form.jpg?direct&960 |}}
 <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 //Pds\Library// is the namespace of this exampe that has to be adapted to your needs!
 +\\
 +<sxh php; highlight: [10,18]>
 +<?php namespace Pds\Library\Controllers;
 +
 +use Backend\Classes\Controller;
 +use BackendMenu;
 +
 +class Books extends Controller
 +{
 +    public $implement = ['Backend\Behaviors\ListController',
 +                         'Backend\Behaviors\FormController',
 +                         'Backend\Behaviour\RelationController']; // this line adds the relation behaviour
 +    
 +    public $listConfig = 'config_list.yaml';
 +    public $formConfig = 'config_form.yaml';
 +    
 +    //add configuration of relation for Books
 +    // this file has to be created then manually inside the
 +    // [namespace]\controllers\[controllername] folder
 +    public $relationConfig = 'config_relation.yaml'; 
 +
 +    public function __construct()
 +    {
 +        parent::__construct();
 +        BackendMenu::setContext('Pds.Library', 'library-main-menu-item');
 +    }
 +}
 +</sxh>
 \\ \\
 ===== 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: $/pds/library/models/description/fields.yaml         form: $/pds/library/models/description/fields.yaml
         list: $/pds/library/models/description/columns.yaml         list: $/pds/library/models/description/columns.yaml
 +
 +...
 </sxh> </sxh>