# Fields

{% hint style="success" %}
This is the official documentation of the `agent_ruby` Ruby agent.
{% endhint %}

Forest Admin is a platform to administrate your business operations efficiently; it provides powerful features to ease data navigation and implement high level views.

When designing databases and APIs, the way to go is usually to push for normalization. This means ensuring there is no redundancy of data (all data is stored in only one place), and that data dependencies are logical.

On the other hand, graphical user interfaces usually need duplication and shortcuts to be user-friendly.

To bridge that gap, Forest Admin allows adding, moving, removing, and overriding behaviors from fields.

### Minimal example

#### Traditional Syntax

Using full context methods with `customize_collection`:

```ruby
include ForestAdmin::Types

@create_agent.customize_collection('user') do |collection|
  collection.add_field(
    'fullName',
    ComputedDefinition.new(
      column_type: 'String',
      dependencies: ['firstName', 'lastName'],
      values: proc { |records| records.map { |record| "#{record['firstName']} #{record['lastName']}" } }
    )
  )
    # Make it writable
    .replace_field_writing('fullName') do |value, context|
      firstName, lastName = value.split(' ')

      { firstName: firstName, lastName: lastName }
    end
    # Add validators
    .add_field_validation('fullName', Operators::PRESENT)
    .add_field_validation('fullName', Operators::SHORTER_THAN, 30)
    .add_field_validation('fullName', Operators::LONGER_THAN, 2)
    # Make it filterable and sortable
    .emulate_field_filtering('fullName')
    .emulate_field_sorting('fullName')
    # Remove previous fields
    .remove_field('firstName', 'lastName')
end
```

#### DSL Syntax

Using simplified DSL with `collection`:

```ruby
@create_agent.collection :user do |collection|
  # Add computed field
  collection.computed_field :fullName,
    type: 'String',
    depends_on: [:firstName, :lastName] do |records|
      records.map { |record| "#{record['firstName']} #{record['lastName']}" }
    end

  # Add validators
  collection.validates :fullName, :present
  collection.validates :fullName, :shorter_than, 30
  collection.validates :fullName, :longer_than, 2

  # Make it filterable and sortable
  collection.emulate_field_filtering 'fullName'
  collection.emulate_field_sorting 'fullName'

  # Remove previous fields
  collection.hide_fields :firstName, :lastName
end
```

**Note:** For advanced operations like `replace_field_writing`, use the traditional `customize_collection` syntax.
