Home platformOS Logo

Properties

Last edit: Jun 05, 2020

Properties are used to persist data in platformOS.

Defining a Property

Properties are defined in YML configuration files for Model Schemas. You have to provide a name and a type. For example:

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

The above configuration adds three properties: "name" of type string, "enabled" of type boolean, 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
array Arrays hold lists of variables of any type. See Arrays [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. It is recommended to store date and time in one format, so if you provide it in different formats, platformOS will convert it to ISO 8601; that’s what GraphQL expects as well. Please note the to_time filter which is very powerful in terms of parsing time. You can display dates/times in any format you want using the localize filter. "2017-07-07 14:00:00 +0000"
float Real numbers 1.0
integer Whole numbers that can be positive, negative, or 0 1
upload See User Uploads
string A UTF-8 character sequence "Some String"

Grouping into models

You can group your Properties into Custom Models.

Form

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

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

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

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

Fetching a Property with GraphQL depending on type

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 family of property defined in (GraphQL PropertiesInterface)[/api-reference/graphql/propertiesinterface.html], for example:

query get_models {
  models(
    per_page: 20,
    filter: {
      model_schema_name: { value: "employee" }
    }
  ) {
    results {
      name: property(name: "name")
      age: property_int(name: "age")
      enabled: property_boolean(name: "enabled")
    }
  }
}

Filtering Properties with GraphQL

You can filter GraphQL results based on object properties values. All options are defined in GraphQL PropertyFilterInput. Some examples:

value - matches the value of given property.

query get_all_johns {
  models(
    per_page: 20,
    filter: {
      properties: [{ name: "name", value: "John" }]
    }
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

value_int - matches the value of given property.

query get_all_models_with_age_14 {
  models(
    per_page: 20,
    filter: {
      properties: [{ name: "age", value_int: 14 }]
    }
  ) {
    results {
      first_name: property(name: "name")
      age: property(name: "age")
    }
  }
}

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

query get_all_johns_and_annas {
  models(
    per_page: 20,
    filter: {
      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 {
  models(
    per_page: 20,
    filter: {
      properties: [{ name: "age", range: { gte: $adult_age_treshold, lt: 60 } }]
    }
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

range uses ISO 8601 date-time formats, for example:

{
  name: "last_time_active",
  range: {
    lte: "2019-10-02T08:13:00",
    gte: "2019-09-01T08:13:00"
  }
}

exists

query get_all_with_name {
  models(
    per_page: 20,
    filter: {
      properties: [{ name: "name", exists: true }]
    }
  ) {
    results {
      first_name: property(name: "name")
    }
  }
}

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

Contribute to this page

Github Icon

Questions?

We are always happy to help with any questions you may have.

contact us