system/classes/Model.php
protected function _getModels($attributeName, $relatedObjName = false, $query = false, $loadMap = false)
    {
      $def = $this->model_attributes[$attributeName];
      $result = [];

      if ($relatedObjName) {
        // If the relationship is one-to-many.
        if (isset($def['via'])) {
          $result = $this->_getModelsFromTableColumn($attributeName, $relatedObjName, $def['via'], $query, $loadMap);
        }

        else if (isset($def['using'])) {
          $result = $this->getModelsFromCustomRelationship($attributeName, $relatedObjName, $query, $loadMap);
        }

        // If the relationship is many-to-many.
        // OR if the relationship is one-to-many and no 'owner' type column is set,
        // meaning there needs to be a relation table.
        else {
          $result = $this->_getModelsFromRelationTable($attributeName, $relatedObjName, $query, $loadMap);
        }
      }

      // If there is no data to return, return an empty collection
      if ($result == null) {
        $this->$attributeName = new \Cora\Collection();
        $result = $this->model_data[$attributeName];
      } 
      return $result;
    }
protected function _getModels($attributeName, $relatedObjName = false, $query = false, $loadMap = false)
    {
      $def = $this->model_attributes[$attributeName];
      $result = [];

      if ($relatedObjName) {
        // If the relationship is one-to-many.
        if (isset($def['via'])) {
          $result = $this->_getModelsFromTableColumn($attributeName, $relatedObjName, $def['via'], $query, $loadMap);
        }

        else if (isset($def['using'])) {
          $result = $this->getModelsFromCustomRelationship($attributeName, $relatedObjName, $query, $loadMap);
        }

        // If the relationship is many-to-many.
        // OR if the relationship is one-to-many and no 'owner' type column is set,
        // meaning there needs to be a relation table.
        else {
          $result = $this->_getModelsFromRelationTable($attributeName, $relatedObjName, $query, $loadMap);
        }
      }

      // If there is no data to return, return an empty collection
      if ($result == null) {
        $this->$attributeName = new \Cora\Collection();
        $result = $this->model_data[$attributeName];
      } 
      return $result;
    }
Uses an attribute's definition to correctly fetch a collection of models from a plural relationship.

@param $attributeName string An attribute on the model that is defined as a plural model relationship.
@return Collection (populated with Models)