Add fields
How does it work?
Field
Description
Examples
Adding a field by concatenating other fields
Traditional Syntax
include ForestAdmin::Types
# User Collection has the following structure: { id, firstName, lastName }
@create_agent.customize_collection('user') do |collection|
collection.add_field(
'displayName',
ComputedDefinition.new(
# Type of the new field
column_type: 'String',
# Dependencies which are needed to compute the new field (must not be empty)
dependencies: %w[firstName lastName],
# Compute function for the new field
# Note that the function computes the new values in batches: the return value must be
# an array which contains the new values in the same order than the provided records.
values: proc { |records| records.map { |record| "#{record["firstName"]} #{record["lastName"]}" } }
)
)
endDSL Syntax
Adding a field that depends on another computed field
Traditional Syntax
DSL Syntax
Adding a field that depends on a many-to-one relationship
Traditional Syntax
DSL Syntax
Adding a field that depends on a one-to-many relationship
Traditional Syntax
DSL Syntax
Adding a field fetching data from an API
Traditional Syntax
DSL Syntax
Performance
Last updated