Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



83.4k

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



34.7k

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



34.7k
Accepted
answer

hey, i was solved it

Thanks