Ouzo\Db\RelationFactory::create PHP Method

create() public static method

public static create ( $relationType, $relation, $relationParams, $primaryKeyName )
    public static function create($relationType, $relation, $relationParams, $primaryKeyName)
    {
        if ($relationType == 'hasOne') {
            return self::hasOne($relation, $relationParams, $primaryKeyName);
        }
        if ($relationType == 'belongsTo') {
            return self::belongsTo($relation, $relationParams);
        }
        if ($relationType == 'hasMany') {
            return self::hasMany($relation, $relationParams, $primaryKeyName);
        }
        throw new InvalidArgumentException("Invalid relation type: {$relationType}");
    }

Usage Example

コード例 #1
0
ファイル: Relations.php プロジェクト: letsdrink/ouzo
 private function _addRelations(array $params, $primaryKeyName)
 {
     foreach (self::$relationNames as $relationName) {
         if (isset($params[$relationName])) {
             foreach ($params[$relationName] as $relation => $relationParams) {
                 $this->_addRelation(RelationFactory::create($relationName, $relation, $relationParams, $primaryKeyName));
             }
         }
     }
 }