User-Defined Properties

User-defined Properties are Properties you can create on demand.

Defining user-defined Properties

Properties are defined in YML configuration files for:

properties:
- name: name
  type: string
- name: enabled
  type: boolean
- name: age
  type: integer

The above configuration adds three custom properties: "name" of type string, "enabled" of type boolan, and "age" of type integer.

Property Types

Each Property is described with the type of data that is stored within the database.
Please note that when processing your Property in Liquid, types are automatically converted to those supported by Liquid Data Types.

The table below lists available data types for Property configuration, that are used to configure fields on the database:

Type Description Example
address See Custom addresses
array Arrays hold lists of variables of any type. [1, 2, 3]
boolean Booleans are used to represent true/false values. true
date Stores Date "2017-07-07"
datetime Stores DateTime with time zone "2017-07-07 14:00:00 +0000"
file See Custom attachments
float Real numbers 1.0
integer Whole numbers that can be positive, negative, or 0 1
photo See Custom Images
string String limited to 255 characters "Some String"
text String limited to 4294967296 characters "Another String"

Grouping into models

You can group your Properties into Custom Models.

FormConfiguration

You can configure Properties settings in Form Configuration similarly to other parameters:

...
fields:
  properties:
    name:
      validation:
        presence: true
    age:
      validation:
        presence: true

{% form %}
  <label for="name">Name</label>
  <input value="{{ form_builder.fields.properties.name.value }}" name="{{ form_builder.fields.properties.name.name }}" id="name" type="text">
  {% if form_builder.errors['properties.name'] %}
    <p>{{ form_builder.errors['properties.name'] }}</p>
  {% endif %}
{% endform %}

For more information see our Form Builder Reference and our Building a Contact Form with Customization tutorial.

Fetching Property with GraphQL

Properties depend on their parent objects and are accessible in the query after mapping the name of the Property with the query attribute name, you can do that with the property method:

query get_customizations {
  customizations(name: "customization_name") {
    results {
      name: property(name: "name")
      age: property(name: "age")
      enabled: property(name: "enabled")
    }
  }
}

Filtering Property with GraphQL

You can filter GraphQL results based on object properties states.
Each object in the properties array is connected with a Property through its name. Additional options are:

value - matches the value of given property

query get_all_johns {
  customizations(
    is_deleted: false
    properties: [{ name: "name", value: "John" }]
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

values - matches array of values with given values_operator: OR or AND.

query get_all_johns_and_annas {
  customizations(
    is_deleted: false
    properties: [{ name: "name", values: ["John", "Anna"], values_operator: OR }]
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

range - available options for range are: lt, lte, gt, gte:

query get_all_adults_below_60 {
  customizations(
    is_deleted: false
    properties: [{ name: "age", range: { gte: $adult_age_treshold, lt: 60 } }]
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

exists

query get_all_with_name {
  customizations(
    is_deleted: false
    properties: [{ name: "name", exists: true }]
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

Please note that the above examples are only valid for Properties defined on CustomModelType. Please refer to GraphQL schema in order to filter Properties defined on different parents than CustomModelType.

Questions?

We are always happy to help with any questions you may have. Check out our Help page, or contact us.