/** * for a given set of relationships, * load them into the entity so find* functions return all requested related data * * make this a getter? It doesn't actually return the array, so keeping as load * * always load parent model(s) * * auto = do nothing * all = load all possible relationships * csv,list = load only these relationships * * * @param string $relationships * @return void */ public final function loadActiveRelationships() { // no need to run this multiple times if (!is_null($this->activeRelations)) { return; } $this->activeRelations = array(); $requestedRelationships = $this->searchHelper->getWith(); $parentModels = $this->getParentModels(false); $modelRelationships = $this->model->getRelations(); $all = false; // load all relationships? // process the private array of relationships switch ($requestedRelationships) { case 'none': $all = false; // gotta load parents if there are any if ($parentModels) { $requestedRelationships = $parentModels; } else { $requestedRelationships = array(); } break; case 'all': $all = true; break; // expect & process a csv string // expect & process a csv string default: // expect csv list or simple string // user_addrs,user_phones $requestedRelationships = explode(',', strtolower($requestedRelationships)); // include parents if there are any if ($parentModels) { $requestedRelationships = array_merge($parentModels, $requestedRelationships); } break; } // load all active relationships as defined by searchHelper foreach ($modelRelationships as $relation) { $tableName = $relation->getTableName(); $modelName = $relation->getModelName(); $aliasName = $relation->getAlias(); // make sure the relationship is approved either as the table name, model name or ALL // table names because end point resources = table names // model name because some auto generated relationships use this name instead // alias is used to STORE the active relationship in case multiple relationships point to the same model // but it is not a valid way for a client to request data if ($all or in_array($tableName, $requestedRelationships) or in_array($modelName, $requestedRelationships)) { // figure out if we have a preferred alias if ($aliasName) { $this->activeRelations[$aliasName] = $relation; } else { $this->activeRelations[$modelName] = $relation; } } } $this->afterloadActiveRelationships(); return true; }