We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

hasMany model

Hi all

I have a problem, I have two tables with model like below:

    namespace Mymodel\Models;

    class Deliverable extends ModelBase
    {
        [...]
        public idTask;
        public function initialize()
        {
            $this->useDynamicUpdate(true);
            $this->hasOne('idTask', 'Mymodel\Models\Task', 'id', ['alias' => 'Task']);
        }
    }

And model two

    namespace Mymodel\Models;

    class Task extends ModelBase
    {
        [....]
        /**
      * @var integer
     */
        public $idDeliverable;
        public function initialize()
        {
                $this->hasMany('idDeliverable', 'Mymodel\Models\Deliverable', 'id', ['alias' => 'deliverable']);
        }

when in controller I call it

    //do something
    $object = Task::findFirstById($id);

    foreach ($object->deliverable as $key => $value) {
            d($value)
    }

It nothing, I don't know while

//
d($object->deliverable)

is object



98.9k

They have different namespaces could be that? namespace Hovercrowd\Models; and Mymodel\Models



58.4k

Sorry, i writing incorrect, i have just edit it but working



58.4k
Accepted
answer

hey, i was solved it

Thanks