Getting records from Many to Many relationship does not work as expected in Phalcon


I have created the phalcon models and relationship as per they provided the document but getting the error "Notice: Undefined property: Phalcon\Mvc\Model\Resultset\Simple::$GroupsMembers in /var/www/html/uno/apps/webservice/controllers/UserController.php on line 245" while trying to fetch related records in many to many relationship.

I have 3 tables users, groups and group_members. group_members contain the relationship for groups and users.I want to get the all subscribed groups for a member therefore I have used below statements in UserController:

    $user = Users::find('id = '.$user_id);
    $subscribed_groups = $user->groupsMembers;
    foreach($groupMembers as $groupMember){
        echo $groupMember->groups->title;

It gives the error mentioned above.

Please visit the link below to see my tables, models and controller.


Thank you Calin Rada ( for answer.

Correct answer is:

find() method is returning an instance of Phalcon\Mvc\Model\Resultset\Simple but findFirst() will return an instance of your object (User in your case).

Detail answer on: