Adds multiple fields into model.

@param array $fields
@param array $defaults

@return $this
500092
public function addFields($fields = [], $defaults = [])
    {
        foreach ($fields as $field) {
            if (is_string($field)) {
                $this->addField($field, $defaults);
                continue;
            }

            if (is_array($field) && isset($field[0])) {
                $name = $field[0];
                unset($field[0]);
                $this->addField($name, $field);
                continue;
            }
        }

        return $this;
    }
1338608
public function addField(Field ...$fields)
    {
        collect($fields)->map(function ($field) {
            $this->group['fields']->put($field->key(), $field->get());
        });

        return $this;
    }
879302
public function aliasFields($fields, $defaultAlias = null)
    {
        $aliased = [];
        foreach ($fields as $alias => $field) {
            if (is_numeric($alias) && is_string($field)) {
                $aliased += $this->aliasField($field, $defaultAlias);
                continue;
            }
            $aliased[$alias] = $field;
        }

        return $aliased;
    }
1291668
public function addField($n, $defaults = [])
    {
        if ($defaults && !is_array($defaults)) {
            $defaults = [$defaults];
        }
        $defaults['join'] = $this;

        return $this->owner->addField($this->prefix.$n, $defaults);
    }
823083
public function addFields(array $fields)
    {
        array_walk(
            $fields,
            function ($field, $key) {
                $this->addField($key, $field);
            }
        );
    }
1306410
public function addField($field, $defaults = [])
    {
        // compatibility: for field types
        $class = $this->_default_seed_addField;
        if (is_array($defaults) && isset($defaults['type'])) {
            switch (strtolower($defaults['type'])) {
                case 'boolean':
                    $class = 'Boolean';
                    break;
            }
        }

        $field_object = $this->factory($this->mergeSeeds($defaults, $class), null, '\atk4\data\Field');
        $this->add($field_object, $field);

        return $field_object;
    }
711409
public function setDefaults(array $defaults)
    {
        foreach ($defaults as $option => $value) {
            $this->setDefault($option, $value);
        }

        return $this;
    }
234690
public function addField($field, $default = null)
    {
        if ($default !== null && (is_array($default) || is_object($default))) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Default value should be scalar, %s given.',
                    gettype($default)
                )
            );
        }

        $defaultProfile = [
            'Field' => '',
            'Type' => '',
            'Collation' => 'utf8_unicode_ci',
            'Null' => 'NO',
            'Key' => '',
            'Default' => '',
            'Extra' => '',
            'Privileges' => 'select,insert,update,references',
            'Comment' => '',
        ];

        if (is_string($field)) {
            $field = array_merge(
                $defaultProfile,
                [
                    'Field' => $field,
                    'Type' => gettype($default),
                    'Default' => $default,
                ]
            );
        }

        if (is_array($field) || is_object($field)) {
            $field = array_merge($defaultProfile, (array) $field);
        }

        $field = (object) $field;

        $this->fields[$field->Field] = $field;

        return $this;
    }
733607
public function add($object, $defaults = [])
    {
        if (!is_array($defaults)) {
            $defaults = ['name' => $defaults];
        }

        $defaults['join'] = $this;

        return $this->owner->add($object, $defaults);
    }
721112
public function addFields(array $fields)
    {
        $fields = Validate::arrToLower($fields);
        Validate::types(array_values($fields));
        $fields = array_diff_assoc($fields, $this->schema());
        if (!empty($fields))
        {
            $config         = $this->getConfig();
            $config->schema = array_merge($this->schema(), $fields);
            $data = $this->getData();
            foreach ($data as $key => $object)
            {
                foreach($fields as $name => $type)
                    $data[$key]->{$name} = (Validate::isNumeric($type)) ? 0 : null;
            }
            $this->databaseDocument->put($data);
            $this->databaseConfig->put($config);
        }
        return true;
    }
213531
public function addDefaults(array $defaults): self
    {
        // TODO : faire un assert que $name est bien une string sinon lever une exception !!!!
        foreach ($defaults as $name => $default) {
            $this->defaults[$name] = $default;
        }

        return $this;
    }
233225
public function fields($fields = [])
    {
        $this->builder->select([]);
        $this->casts = [];

        if (empty($fields)) {
            foreach ($this->model->fields() as $field) {
                $this->assignField($field);
            }

            return $this;
        }

        foreach ($fields as $field) {
            $this->assignField($this->model->field($field));
        }

        return $this;
    }
1246422
public function setFields($fields)
    {
        if ($fields instanceof RecordFields) {
            $this->fields = $fields;
        } else {
            if (is_array($fields)) {
                $fields       = new RecordFields($fields);
                $this->fields = $fields;
            }
        }
        return $this;
    }
174803
public function setFields(array $fields)
    {
        $this->fields = [];

        foreach ($fields as $type => $field) {
            //Remove empty and repeated fields
            $this->fields[$type] = array_unique(array_filter(explode(',', $field)));
        }

        return $this;
    }
1192550
public function addDefaults(array $defaults)
    {
        foreach ($defaults as $name => $default) {
            $this->defaults[$name] = $default;
        }
        $this->compiled = null;

        return $this;
    }
908721
public function setDefaults(array $defaults)
    {
        $this->defaults = array_merge($this->_global_defaults, $defaults, $this->defaults);
        return $this;
    }
553390
public function fields($fields)
    {
        $fields = is_array($fields) && func_num_args() === 1 ? $fields : func_get_args();
        $this->_parts['fields'] = Set::merge($this->_parts['fields'], $fields);
        return $this;
    }