mysql - Retrieve related data-set on Phalcon -
i have 2 tables. wanted return not parent data "lists", including relationship "listtypes". how can that?
$d = self::find(); // works - missing relations, see expected result.
tables:
- lists
- list types
with following code relations.
// models/lists.php <?php use phalcon\mvc\model; class lists extends model { public function initialize() { $this->hasone('type_id', 'listtypes', 'id'); } public function getdata() { $d = self::find(); } } ?> // models/listtypes.php <?php use phalcon\mvc\model; class listtypes extends model { public function initialize() { $this->belongsto('id', 'lists', 'type_id'); } } ?>
current results:
array ( [0] => array ( [id] => 1 [name] => airbus [type_id] => 1 ) [1] => array ( [id] => 2 [name] => bmw [type_id] => 2 ) )
expected results: -- want
array ( [0] => array ( [id] => 1 [name] => airbus [type_id] => 1 [type_name] => airplane ) [1] => array ( [id] => 2 [name] => bmw [type_id] => 2 [type_name] => car ) )
you can use recursive function related models long set alias child relation inside every parent model. php / phalcon - automatically nesting objects
Comments
Post a Comment