---
title: Relations
summary: Follow an object to its building storey, its type object and the elements that bound a space, in GET and in WHERE.
order: 40
terms: [bql, type-object, occurrence]
see-also: [tutorials/bql/properties-and-quantities, tutorials/bql/grouping-and-aggregates, reference/bql/building-storeys, reference/bql/type-objects, reference/bql/openings-and-fillings]
---

# Relations

An IFC model is a graph: a door sits in a wall, the wall on a storey, the storey in a building; a wall occurrence points at a wall type that carries the properties shared by all walls of that kind. BQL follows these relations with a path prefix in front of any feature you already know.

## The storey of an object

`buildingStorey.` in front of a feature reads that feature from the storey that contains the object:

```bql {#storey-name}
GET qid, attribute.Name, buildingStorey.attribute.Name WHERE type = IFCDOOR
```

The same prefix filters: `buildingStorey.attribute.Name = "00 begane grond"` keeps the objects on the ground floor. The storey also carries a calculated level number, `buildingStorey.calculated.property.level`, which is more robust than a name when models differ in naming; [[bql:building-storeys]] explains how storeys are ordered and matched across models. `building.`, `site.` and `project.` work the same way for the levels above the storey.

## The type object

In IFC an occurrence (this wall) is linked to a type object (this kind of wall). The type object is the place authoring tools put the properties that all occurrences share, so a query on occurrences often needs a value from the type:

```bql {#type-object}
GET qid, attribute.Name, typeObject.attribute.Name WHERE type = IFCWALL
```

`typeObject.property.*` reaches the type's property sets in the same way. Keep the direction in mind: query the occurrence (`type = IFCWALL`) and reach the type through `typeObject.`; a query with `type = IFCWALLTYPE` returns the type objects themselves, which have no geometry and are not what you count or colour. [[bql:type-objects]] covers how type and occurrence properties merge.

## Related sets

Some relations lead to many objects: the materials of a wall, its classifications, the openings in it, the elements that bound a space. In `GET` such a relation returns a **list** per object:

```bql {#materials}
GET qid, attribute.Name, material.name, classification.identity WHERE type = IFCWALL
```

A wall of the demo model comes back with `material: [{"name": "03 Metselwerk - kalkzandsteen C"}]` and `classification: [{"identity": "21.12"}]` — one entry per material layer and per classification reference. Both work in `WHERE` as well: `material.name CONTAINS "hout"` keeps the wooden ones, `classification.identity = "21.12"` the 423 walls of that NL-SfB code.

The relations of the IFC structure work the same way: `hasOpenings` on a wall lists its openings and `fillings` the doors and windows that fill them, `fillsVoid` goes the other way from a door to its opening, and `spaceBoundary.relatedBuildingElement` steps from a space to the walls, slabs and windows that bound it. The naming follows the IFC relationships; [[bql:openings-and-fillings]] draws the picture, and [[bql:sub-features]] has the quantifiers (`.any`, `.all`, `.count`) that ask about a related set instead of listing it.

```note
A relation returns nothing when the model does not carry it. Schependomlaan has no `IfcRelSpaceBoundary` entities and no explicit filling relations, so `spaceBoundary` and `fillsVoid` come back empty on it — which is itself worth knowing about a model before you write a check that depends on them.
```

A related set can also be summed up in place, `spaceBoundary(SUM(quantity.*.Area))` for the boundary area of each space; the next lesson introduces the aggregate functions this uses.

## Your turn

```lesson {#lesson-1}
goal: List every door with its name and the name of the storey it is on.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCDOOR
hints: |
  - Put buildingStorey. in front of attribute.Name.
  - The prefixed feature is a second GET item.
solution: |
  GET qid, attribute.Name, buildingStorey.attribute.Name WHERE type = IFCDOOR
accept: |
  - GET qid, attribute.Name, buildingStorey(attribute.Name) WHERE type = IFCDOOR
```

```lesson {#lesson-2}
goal: List the windows on the ground floor, the storey named "00 begane grond".
show: viewer
check: objects
starter: |
  GET qid, attribute.Name WHERE type = IFCWINDOW
hints: |
  - The storey name is a condition on buildingStorey.attribute.Name.
  - Combine it with the type condition using AND.
  - The calculated level of that storey is 0, which is another way to say the same thing.
solution: |
  GET qid, attribute.Name WHERE type = IFCWINDOW AND buildingStorey.attribute.Name = "00 begane grond"
accept: |
  - GET qid, attribute.Name WHERE type = IFCWINDOW AND buildingStorey.calculated.property.level = 0
```

This round shows its result in the 3D viewer: the objects your query selected are coloured, the rest of the model stays grey, and the view is framed around them. It is the fastest way to see whether a condition means what you thought — a query with the wrong storey is obvious in one glance.

```lesson {#lesson-3}
goal: List every wall with its own name and the name of its type object.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCWALL
hints: |
  - The type object is reached with typeObject.
  - Its name is typeObject.attribute.Name.
solution: |
  GET qid, attribute.Name, typeObject.attribute.Name WHERE type = IFCWALL
accept: |
  - GET qid, attribute.Name, typeObject(attribute.Name) WHERE type = IFCWALL
```

```lesson {#lesson-4}
goal: List every wall with its name and the material or materials it is made of.
show: json
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCWALL
hints: |
  - The relation is called material, and the field of a material is name.
  - A wall with several layers gets a list, which is why this round shows JSON.
solution: |
  GET qid, attribute.Name, material.name WHERE type = IFCWALL
accept: |
  - GET qid, attribute.Name, material(name) WHERE type = IFCWALL
```

A relation that leads to many objects nests a list in the record, which the JSON shows better than a table. The order of the members is the model's, not something you can rely on — and the round accepts any order for that reason. Note that only 282 of the 934 walls carry a material at all: the record of the others simply has no `material` key.

## You can now

- Read a feature of the storey, building, site or project an object belongs to, and filter on it.
- Reach the type object of an occurrence and its properties.
- List the objects a relation leads to, and chain relations.

Next: [Grouping and aggregates](grouping-and-aggregates.md), where rows become counts and sums.
