original_string: protected function setModelAttributes($model, $saveData)
      {
          $this->modelsToSave[] = $model;
  
          if (!is_array($saveData)) {
              return;
          }
  
          if ($model instanceof HalcyonModel) {
              $model->fill($saveData);
              return;
          }
  
          $attributesToPurge = [];
          $singularTypes = ['belongsTo', 'hasOne', 'morphTo', 'morphOne'];
  
          foreach ($saveData as $attribute => $value) {
              $isNested = $attribute == 'pivot' || (
                  $model->hasRelation($attribute) &&
                  in_array($model->getRelationType($attribute), $singularTypes)
              );
  
              if ($isNested && is_array($value)) {
                  $this->setModelAttributes($model->{$attribute}, $value);
              }
              elseif ($value !== FormField::NO_SAVE_DATA) {
                  if (Str::startsWith($attribute, '_')) {
                      $attributesToPurge[] = $attribute;
                  }
                  $model->{$attribute} = $value;
              }
          }
  
          if ($attributesToPurge) {
              $this->deferPurgedSaveAttributes($model, $attributesToPurge);
          }
      }
code: protected function setModelAttributes($model, $saveData)
      {
          $this->modelsToSave[] = $model;
  
          if (!is_array($saveData)) {
              return;
          }
  
          if ($model instanceof HalcyonModel) {
              $model->fill($saveData);
              return;
          }
  
          $attributesToPurge = [];
          $singularTypes = ['belongsTo', 'hasOne', 'morphTo', 'morphOne'];
  
          foreach ($saveData as $attribute => $value) {
              $isNested = $attribute == 'pivot' || (
                  $model->hasRelation($attribute) &&
                  in_array($model->getRelationType($attribute), $singularTypes)
              );
  
              if ($isNested && is_array($value)) {
                  $this->setModelAttributes($model->{$attribute}, $value);
              }
              elseif ($value !== FormField::NO_SAVE_DATA) {
                  if (Str::startsWith($attribute, '_')) {
                      $attributesToPurge[] = $attribute;
                  }
                  $model->{$attribute} = $value;
              }
          }
  
          if ($attributesToPurge) {
              $this->deferPurgedSaveAttributes($model, $attributesToPurge);
          }
      }
code_tokens: protected function setModelAttributes ( $ model , $ saveData ) { $ this -> modelsToSave [ ] = $ model ; if ( ! is_array ( $ saveData ) ) { return ; } if ( $ model instanceof HalcyonModel ) { $ model -> fill ( $ saveData ) ; return ; } $ attributesToPurge = [ ] ; $ singularTypes = [ 'belongsTo' , 'hasOne' , 'morphTo' , 'morphOne' ] ; foreach ( $ saveData as $ attribute => $ value ) { $ isNested = $ attribute == 'pivot' || ( $ model -> hasRelation ( $ attribute ) && in_array ( $ model -> getRelationType ( $ attribute ) , $ singularTypes ) ) ; if ( $ isNested && is_array ( $ value ) ) { $ this -> setModelAttributes ( $ model -> { $ attribute } , $ value ) ; } elseif ( $ value !== FormField :: NO_SAVE_DATA ) { if ( Str :: startsWith ( $ attribute , '_' ) ) { $ attributesToPurge [ ] = $ attribute ; } $ model -> { $ attribute } = $ value ; } } if ( $ attributesToPurge ) { $ this -> deferPurgedSaveAttributes ( $ model , $ attributesToPurge ) ; } }
docstring: Sets a data collection to a model attributes, relations are also set.
  
  @param \October\Rain\Database\Model $model Model to fill.
  @param array $saveData Attribute values to fill model.
  @return void
docstring_tokens: Sets a data collection to a model attributes relations are also set .