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.

how & where to define addHasMany relation ship

how & where to define addHasMany relation ship



1.5k
edited Sep '14

addHasMany is an abstract method defined in interface model, I want to know the usage and where to define it



82.7k

addHasMany is not an abstract method defined in interface model: http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5ModelInterface.html#methods



1.5k
edited Sep '14

sorry for mistake check link to see addHasMany method http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Manager.html



1.5k
edited Sep '14

I was not able to find addHasMany method useage there



82.7k
Accepted
answer
<?php
class Robots extends \Phalcon\Mvc\Model
{

    public function initialize()
    {
        $this->_modelsManager->addHasMany($this, 'id', 'RobotsParts', 'robots_id', null);
    }

}


1.5k
edited Sep '14

Thank you very much for the explanation!



1.5k
edited Sep '14

```php <?php class Robots extends \Phalcon\Mvc\Model {

public function initialize() { $this->modelsManager->addHasMany($this, 'id', 'RobotsParts', 'robotsid', null); }

} ```

getting error

[Wed, 10 Sep 14 10:21:35 +0200][ERROR] [2] Phalcon\Mvc\Model\Manager::addHasMany(): phalcongetclass expects an object ( Line: [99])