We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36692
    • 13 Posts
    I've been struggling to understand the issue of deeply related data and how to access/iterate it cleanly in the most xPDO way. I've read many threads and discussions but still can't seem to get what I want working.

    Essentially, I've got Users, who belong to at most one Group, and the Group has many Permissions.

    So I believe I should be able to do this:

    // Not sure if these are required
    $modx->setOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS, true);
    $modx->setOption(xPDO::OPT_HYDRATE_FIELDS, true);
    
    $obj = $modx->getObjectGraph('User', '{ "Group": { "Permissions": {}}}', $id);
    
    $permissions = $obj->Group->Permissions;
    
    foreach ($permissions As $permission) {
        echo $permission->get('name');
    }
    
    


    I'm only getting back one permission, but the DB defines 3.

    I'm pretty sure my schema correctly defines the relationships, since I'm pretty far along with the project and have many getCollectionGraph calls working as expected.

    So the question is, am I doing this using the right paradigm or is my method off-base?