コード例 #1
0
ファイル: Action.php プロジェクト: netis-pl/yii2-crud
 /**
  * Returns default fields list by combining model attributes with hasOne relations or just hasMany relations.
  * @param ActiveRecord $model
  * @param bool $extra if false, returns attributes and hasOne relations, if true, returns only hasMany relations
  * @return array default list of fields
  */
 public static function getDefaultFields($model, $extra = false)
 {
     $fields = $extra ? [] : $model->attributes();
     foreach ($model->relations() as $relation) {
         $activeRelation = $model->getRelation($relation);
         if (!$extra && $activeRelation->multiple || $extra && !$activeRelation->multiple) {
             continue;
         }
         $fields[] = $relation;
     }
     return $fields;
 }