php - Phalcon: How to get first model in 1-n relation -
i have following models
class post extends \phalcon\mvc\model { ... $this->hasmany('id', 'postmedia', 'parent_id'); } class postmedia extends \phalcon\mvc\model { ... $this->belongsto('parent_id', 'post', 'id'); }
to related entries following
post::find(1)->postmedia;
but how first model? following code results in phalcon\mvc\model\resultset\simple
object, need postmedia object.
post::find(1)->getpostmedia(['limit' => 1]);
there getfirst()
, getlast()
, other useful methods in phalcon\mvc\model\resultset\simple
class. there problem in code: post::find(1)
returns resultset, not post object, correct code first related object this:
$first_media = post::findfirst(1)->postmedia->getfirst();
Comments
Post a Comment