I want to implement parent child relationship in OctoberCMS. I have two model client and session. this is one to many relationship. One client have multiple session. My target is when clicking on a row of client list it will expand the session child row. Here is code of my models -
Client Model
<?php
namespace Smriad\Pracitioner\Models;
use Model;
class Client extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;
public $timestamps = false;
/**
* @var array Validation rules
*/
public $rules = [
];
/**
* @var string The database table used by the model.
*/
public $table = 'smriad_pracitioner_client';
public $hasMany = [
'session' => ['Smriad\Pracitioner\Models\Session', 'key' => 'client_id']
// ^ you can use house instead houses for relation name
];
}
Session Model
<?php namespace Smriad\Pracitioner\Models;
use Model;
/**
* Model
*/
class Session extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var array Validation rules
*/
public $rules = [
];
/**
* @var string The database table used by the model.
*/
public $table = 'smriad_pracitioner_client_session';
public $belongsTo = [
'client' => ['Smriad\Pracitioner\Models\Client', 'key' => 'client_id']
// ^ you can use house instead houses for relation name
];
}