Skip to content

Deprecated since 7.2

This page documents the classic module layer (CBController and cbInit()). It still works in every 7.x release, but new code should use resources and pages.

Use instead: Select::make('category_id')->relationship('category', 'name').

How To Implement An One To Many Relationship To Form (E.g : Product <- Category) ​

Products Table - products ​

Field NameDescription
idint(PK)
created_attimestamp
namevarchar(255)
descriptiontext
categories_idint(11)

Categories Table - categories ​

Field NameDescription
idint(PK)
created_attimestamp
namevarchar(255)

Form ​

php
$this->form[] = ['label'=>'Name','name'=>'name','type'=>'text'];
$this->form[] = ['label'=>'Description','name'=>'description','type'=>'textarea'];
$this->form[] = ['label'=>'Category','name'=>'categories_id','type'=>'select','datatable'=>'categories,name'];

Column ​

php
$this->col[] = ['label'=>'Name','name'=>'name'];
$this->col[] = ['label'=>'Description','name'=>'description'];
$this->col[] = ['label'=>'Category','name'=>'categories_id','join'=>'categories,name'];

What's Next ​

Table Of Contents ​

Released under the MIT License.