Ownership notation

Learn how to access properties using the apostrophe-s notation.

The ownership notation is a more natural way to access properties in CQL. It is complementary to the possessive notation and can be used interchangeably or in combination with it.

The syntax follows the same pattern as the possessive form in English. It consists of the variable name followed by an apostrophe and an "s" ('s) and the property name.

Here is a basic example that accesses the interests property of the user variable:

user's interests
Try in Playground

You can also chain multiple property accesses together to access nested properties:

user's address's city
Try in Playground

Alternatively, you can use the possessive form for an even more natural sentence:

property city of user's address
Try in Playground

To combine the ownership notation with other technical notations, such as the bracket notation, you can use parentheses:

(user's interests)[0]
Try in Playground

In English, it is common to drop the "s" after the apostrophe when the word ends with an "s". You can do the same in CQL to make the queries more natural:

let status = ["code": "active"];
status' code
Try in Playground

Keep in mind that dropping the extra "s" after an apostrophe is just syntax sugar. It is not a requirement, so you can keep the "s" if you prefer.

Consider using the ownership notation when:

  • The property name is a valid identifier and is known in advance.
  • The property is not deeply nested.
  • You prefer writing queries using a more natural language style.
  • You want to combine it with the possessive notation for a more natural sentence.