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

Model navigation properties

Hi,

I have three entities in my DB:

robot <<------->> charateristic_value <<------->> charateristic

<<-------->> means many-to-many.

The DB schema for this is:

  • Table: robot
  • Table: robot_charateristic_value (many-to-many between robot and charateristic_value)
  • Table: charateristic_value
  • Table: charateristic_charateristic_value (many-to-many between charateristic and charateristic_value)
  • Table: charateristic

The Models, with all hasManyToMany and belgonsTo configurated in their initialize methods, are:

  • Robot
  • RobotCharateristicValue
  • CharateristicValue
  • CharateristicCharateristicValue
  • Charateristic

I am inside Robot model. I'm implementing a Method that returns all Charateristic of this Robot with charateristic_name = "COLOR". I'd like to do something like that:

    $this->RobotCharateristicValue->CharateristicValue->CharateristicCharateristicValue->Charateristic(array(
         'CharateristicName = "EYE"',
     ));

Is there any way to do something like that? Or is it necessary to use the ::query() method?

Thank you.



43.9k

Hi,

Unfortunately, this nice feature (called "named scope" by yii framework: https://www.yiiframework.com/doc/guide/1.1/en/database.ar#named-scopes) is not available in phalcon, you will have to do it by hand in your own function.