Bluz\Db\Relations::getModelClass PHP Метод

getModelClass() публичный статический Метод

Get information about Model classes
public static getModelClass ( string $model ) : string
$model string
Результат string
    public static function getModelClass($model)
    {
        if (!isset(self::$modelClassMap[$model])) {
            // try to detect
            $className = '\\Application\\' . $model . '\\Table';
            if (!class_exists($className)) {
                throw new RelationNotFoundException("Related class for model `{$model}` not found");
            }
            self::$modelClassMap[$model] = $className;
        }
        return self::$modelClassMap[$model];
    }

Usage Example

Пример #1
0
 /**
  * findRelation
  *
  * @param  Row $row
  * @param  string $relation
  * @return array
  * @throws Exception\RelationNotFoundException
  */
 public static function findRelation($row, $relation)
 {
     $model = $row->getTable()->getModel();
     /** @var \Bluz\Db\Table $relationTable */
     $relationTable = Relations::getModelClass($relation);
     $relationTable::getInstance();
     if (!($relations = Relations::getRelations($model, $relation))) {
         throw new RelationNotFoundException("Relations between model `{$model}` and `{$relation}` is not defined");
     }
     // check many-to-many relations
     if (sizeof($relations) == 1) {
         $relations = Relations::getRelations($model, current($relations));
     }
     $field = $relations[$model];
     $key = $row->{$field};
     return Relations::findRelations($model, $relation, [$key]);
 }