We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hello

    Following the instructions at http://rtfm.modx.com/display/xPDO20/getOne

    I have this behaviour and I’m curious to understand why it goes this way...

    When I do
    $projects = $modx->getCollection('cpoProject',$c);
    
    $list = array();
    foreach ($projects as $project) {
        $owner = $project->getOne('Company'); // Company is the alias for aggregate relashionship in object 'cpoProject'
        $projectArray = $project->toArray();
        $projectArray['owner'] = $owner->get('name');
        $list[]= $projectArray;
    }
    return $this->outputArray($list,$count);
    


    The line "$projectArray[’owner’] = $owner->get(’name’);" is the one I’m asking about...

    It seems I can do both "$projectArray[’owner’] = $owner->get(’name’);" or "$projectArray[’owner’] = $owner->name;"; with the same result... I suppose the good one is "$owner->get(’name’)" but is the other correct too, why or why not?

    Thanks
      • 28215
      • 4,149 Posts
      splittingred Reply #2, 16 years ago
      ->get(’name’) is preferred, as then that allows you to override get() and perform overrides or other logic directly on it should you ever need to change the behaviour of get() or change the ’name’ field.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 1778
        • 659 Posts
        Hi Shaun,
        thanks for your answer... Tonight I’ll go to sleep a bit less idiot smiley