Query Attributes
Attributes are objects that refer back to a given object. In other words, if Object A references Object B, then Object A is considered an attribute of Object B.
Simple diagram to illustrate example.
Attributes are often used to associate additional information with an object without making changes to the object's content type. In other words, they are assertions about an object that are made outside of the scope of the object's direct fields.
Queries
Attributes are so common and useful that COMAND queries have special syntax to access them.
@(Field)ContentType.ObjectField
- @ - Denotes an attribute reference.
- (Field) - Narrows the attribute scope to just attributes that reference the object through a specific field or chain of dot-notation fields. If not provided, any field in the attribute that references the object will match. Field can be a single field or chain of dot-separated fields extending out from the attribute.
- ContentType - The attribute's content type identifier. If not provided, attributes of any content type will match.
- .ObjectField - Optional dot-notation field(s) from the attribute object.
Examples
Given the scenario illustrated above, each example below will set $contacts to a collection of all contacts tagged as 'Family'.
// cQL to get all contacts that have any attributes (tag or otherwise)
$contacts = $repo->get("FROM Contact WHERE @");
// cPath to get all contacts that have any attributes (tag or otherwise)
$contacts = $repo->get("//[:Contact][@]");
// cQL to get all contacts that have a Tag attribute (any tag)
$contacts = $repo->get("FROM Contact WHERE @Tag");
// cQL to get all contacts that have a "Family" Tag attribute, by key
$contacts = $repo->get("FROM Contact WHERE @Tag='Family'");
// more explicit version of the previous, to only match on Tag.Objects
$contacts = $repo->get("FROM Contact WHERE @(Objects)Tag='Family'");
// cQL to get all contacts that have a "Family" Tag attribute, by Title
$contacts = $repo->get("FROM Contact WHERE @Tag.Title='Family'");
// more explicit version of the previous, to only match on Tag.Objects
$contacts = $repo->get("FROM Contact WHERE @(Objects)Tag.Title='Family'");
// cQL to get Family tag by key, then all Objects associated with the tag
$family = $repo->get_first("FROM Tag WHERE .Key()='Family'");
$contacts = $family->Objects;
// same as previous, except ensure we only get contacts
$family = $repo->get_first("FROM Tag WHERE .Key()='Family'");
$contacts = $family->Objects->get("FROM Contacts");
webCOMAND
In webCOMAND, attributes are displayed and managed in the Attributes sidebar of Form View in the Content Manager.