Note that there are some explanatory texts on larger screens.

plurals
  1. POExtending a Model in Phalcon
    primarykey
    data
    text
    <p>How would one make a child-parent relationship between Phalcon MVC models?</p> <p>This is a DB schema I have in mind:</p> <pre><code>explain show; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | length | int(11) | NO | | NULL | | | title | varchar(100) | NO | | NULL | | +---------+--------------+------+-----+---------+-------+ explain show_episode; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | show_id | int(11) | NO | PRI | NULL | | | season | int(11) | NO | | NULL | | | episode | int(11) | NO | | NULL | | +---------+--------------+------+-----+---------+-------+ </code></pre> <p>Each element in <code>show_episode</code> is also present in <code>show</code> table, however there are show records which are only present in <code>show</code>.</p> <p>The idea is to have two Phalcon Model classes:</p> <pre><code>class Show extends Phalcon\Mvc\Model { public $id; public $length; public $title; } class ShowEpisode extends Show { public $season; public $episode; } </code></pre> <p>How would I need to configure those models to be able to retrieve and save episode records like this:</p> <pre><code>// retrieve $episode = ShowEpisode::findFirst(array("id"=&gt;333)); echo $episode-&gt;season; echo $episode-&gt;title; // save $episode-&gt;title = "New Title"; $episode-&gt;season = 3; $episode-&gt;save(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload