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

how & where to define addHasMany relation ship

how & where to define addHasMany relation ship



2.7k
edited Sep '14

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



98.9k

addHasMany is not an abstract method defined in interface model: https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_ModelInterface.html#methods



2.7k
edited Sep '14

sorry for mistake check link to see addHasMany method https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Manager.html



2.7k
edited Sep '14

I was not able to find addHasMany method useage there



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

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

}


2.7k
edited Sep '14

Thank you very much for the explanation!



2.7k
edited Sep '14
<?php
class Robots extends \Phalcon\Mvc\Model
{

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

}

getting error

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