Example #1
0
 /**
  * Does the actual add of the field.
  *
  * @param $modelName
  * @param $fieldName
  *
  * @since 1.1.0
  *
  * @throws \Eddmash\PowerOrm\Exception\FieldDoesNotExist
  * @throws \Eddmash\PowerOrm\Exception\LookupError
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function _generateAddedFields($modelName, $fieldName)
 {
     /** @var $field Field */
     $field = $this->newRegistry->getModel($modelName)->meta->getField($fieldName);
     $opDep = [];
     $preserveDefault = true;
     if ($field->relation !== null && $field->relation->toModel) {
         // depend on related model being created
         $opDep[] = ['target' => $field->relation->toModel->meta->modelName, 'model' => true, 'create' => true];
         // if it has through also depend on through model being created
         if ($field->relation->hasProperty('through') && $field->relation->through != null && !$field->relation->through->meta->autoCreated) {
             $opDep[] = ['target' => $field->relation->through->meta->modelName, 'model' => true, 'create' => true];
         }
     }
     if (!$field->null && !$field->hasDefault() && !$field instanceof ManyToManyField) {
         $def = MigrationQuestion::askNotNullAddition($this->asker, $modelName, $fieldName);
         $field = $field->deepClone();
         $field->default = $def;
         $preserveDefault = false;
     }
     $this->addOperation(AddField::createObject(['modelName' => $modelName, 'name' => $fieldName, 'field' => $field, 'preserveDefault' => $preserveDefault]), $opDep);
 }
Example #2
0
 /**
  * @return StateRegistry
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function getRegistry()
 {
     return StateRegistry::createObject($this->modelStates);
 }