> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datazone.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Backed Objects

> Put a Knowledge Object on top of an existing dataset or view, and add your own editable properties to its rows

# Backed Objects

A **backed object** reads its instances from a dataset or view you already have. Every row of the source is an instance. You pick the columns to expose, choose the primary key, and link the object to other objects. You can also add **custom properties**: editable fields that Datazone stores for each instance, next to the source data.

Use a backed object when the data already lives in Datazone, for example customers loaded by an Extract or orders built by a Pipeline, and you want to:

* give it a business name and a schema that other objects can reference,
* link it to other objects through relationships,
* let users or agents add notes, statuses, or tags to rows that come from somewhere else.

| | Local (standalone) object | Backed object |
| - | - | - |
| Where rows come from | Created through the API or the UI | The source dataset or view |
| Create / delete rows | Yes | No. Rows follow the source |
| Editable fields | Every mutable field | Custom properties only |
| History | Every change to the row | Changes to custom properties |
| YAML | `object_type: STANDALONE` (the default) | `object_type: BACKED` with `settings.source` |

## Create a backed object in the UI

Open **Knowledge Objects** in your project and click **Create**.

**1. Source**

Choose **Backed**, then pick a **Dataset** or a **View** of the project.

![Choosing Backed and a source dataset on the create form](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-create-backed-source.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=7ee21bf4e74d05eb412596f65755e88a)

You need read access to the source. Only datasets and views of the same project are listed.

**2. Details**

Give the object a name, a description, and the branch to deploy on.

**3. Schema**

The form lists every column of the source with its exact ClickHouse type.

* Untick a column to leave it out of the object.
* Rename a field in the text box. The source column keeps its name.
* Click the **key** icon to make a column part of the primary key.
* Click the **tag** icon to make a column the label column.
* Click the **link** icon to point the column at another object's primary key. See [Relationships](#relationships).

Under **Custom properties**, add the editable fields you want to keep for each instance.

![Schema step of a backed object with source columns, relationships and custom properties](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-create-backed-schema.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=b1307664f233917b647f96f6357d39a4)

Click **Create**. Datazone checks the source (see [Source validation](#source-validation)), writes the YAML file to your repository, and deploys it. The object is ready when its migration completes.

## Source fields and custom properties

A backed object has two kinds of fields.

**Source fields** read a column of the source. They have a `source_column` and are always read-only. Their type comes from the column's ClickHouse type, which you set in `db_type`:

| ClickHouse type | Field type |
| - | - |
| `Int*`, `UInt*` | `int` |
| `Float*`, `Decimal*` | `float` |
| `String`, `FixedString`, `UUID`, `Enum*` | `str` |
| `Bool` | `bool` |
| `Date`, `Date32` | `date` |
| `DateTime`, `DateTime64` | `datetime` |
| Anything else (`Array`, `Map`, `Tuple`, `JSON`, …) | `other` |

* A `Nullable(...)` column becomes an optional field. `LowCardinality(...)` is unwrapped.
* An `other` field is shown as is. It cannot be a primary key, have `options`, or hold a relationship.
* Source fields cannot have a `default` or a `db_column`.
* The primary key must be made of source fields.

**Custom properties** are fields without a `source_column`. They are stored by Datazone for each instance and are the only fields you can edit. Each custom property must be `optional` or have a `default`, because rows arrive from the source without a value. Until a row is edited, its custom properties are `NULL` (or their default).

## Define it in YAML

```yaml objects/invoice.yaml theme={null}
name: Invoice
description: The invoice billing an order.

fields:
  # Source fields: read from the source, read-only
  - name: InvoiceID
    source_column: InvoiceID
    db_type: Nullable(String)
    primary_key: true
  - name: OrderID
    source_column: OrderID
    db_type: Nullable(String)
    relationship:
      - object: Order
  - name: CustomerID
    source_column: CustomerID
    db_type: Nullable(Int64)
    relationship:
      - object: Customer
  - name: TotalAmount
    source_column: TotalAmount
    db_type: Nullable(Float64)

  # Custom properties: stored by Datazone, editable
  - name: collection_note
    type: str
    optional: true
  - name: review_status
    type: str
    default: open
    options: [open, in_review, done]

settings:
  object_type: BACKED
  source:
    type: dataset      # or: view
    id: 6ae9e2eac98b6f2992c4f0ec
  label_column: InvoiceID
```

* `settings.source.type` is `dataset` or `view`. `settings.source.id` is the id of the dataset or view.
* Setting `source` is enough. `object_type` becomes `BACKED` on its own.
* For source fields, leave out `type` and `optional`. They are derived from `db_type`.
* `db_type` must match the source column's type exactly, for example `Nullable(Int64)`, not `Int64`.

See the [YAML Reference](https://docs.datazone.co/reference/knowledge-objects/yaml-reference.md) for every attribute.

## Relationships

A relationship field holds the **primary key value** of an instance of another object. `CustomerID` on `Invoice` holds a `Customer`'s `CustomerID`, so a source column that already contains the id is a relationship as is. No extra mapping is needed.

In the **Schema** step, click the **link** icon on a source column. The picker lists the primary key fields of every object in the project, with their types:

![Linking a source column to another object's primary key](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-create-relationship-picker.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=b0bfbdbf9525a223e104b3b24c3dd21f)

To add a relationship that is not in the source, click **Add relationship** under **Custom properties** and pick an object. Datazone adds one custom property for each primary key field of that object, already linked. For an object with a composite key, it adds one field per key field, and together they form one link.

![Add relationship lists the objects of the project and their primary keys](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-add-relationship.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=841e747462b551f5399e615eb3a5e828)

Relationship rules:

* The field type must be `str`, `int`, or `date`. A `str` field can hold any key type. Other types must match the related key's type.
* If the related object has one primary key field, `relationship` only needs `object`.
* If it has a composite key, each field sets `relationship.field` to the key field it holds. Each key field must be covered once.
* When you create or edit an instance, Datazone checks that the value matches an existing instance of the related object. A composite link must be set completely or left empty.

```yaml theme={null}
# OrderLine has a composite key (order_id, line_no)
- name: order_id
  type: str
  optional: true
  relationship:
    - object: OrderLine
      field: order_id
- name: line_no
  type: int
  optional: true
  relationship:
    - object: OrderLine
      field: line_no
```

> [!NOTE]
>
> Relationships hold primary key values for standalone objects too. Objects created before this change stored the related instance key (`_key`). Those values were converted to primary key values.

## Edit instances

Open the object's **Instances** tab and choose **Edit** on a row. Source fields are shown read-only. Custom properties can be changed. A custom relationship field opens a picker over the related object's instances.

![Editing a backed instance: source fields are read-only, custom properties are editable](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-backed-instance-edit.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=9e7daf423c0adb02443b3234a18f14d6)

The picker lists the related object's instances by their label column, or by their key value when the object has no label column. Pick one to set the field to that instance's primary key value.

![Picking a related Orders instance for a relationship field](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-instance-relationship-picker.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=b7c154be9538403e00c86ed129af1453)

Backed rows cannot be created or deleted. They come and go with the source. There is no **Add instances** action and no **Delete** row action for backed objects.

The **Overview** tab shows each field's type, source column, and relationship, and the object's source in the **Meta** panel.

![Overview of a backed object with source columns and relationships](https://mintcdn.com/datazone/cL-gp8k_Xeq_ci1h/images/light/knowledge-object/ko-backed-overview.png?fit=max\&auto=format\&n=cL-gp8k_Xeq_ci1h\&q=85\&s=31bd8f6c8fc78cd8dad91a3cbc6146b6)

## Keeping data fresh

* **Dataset sources** are copied into a table that belongs to the object. Each time the dataset gets a new transaction (an Extract or Pipeline run), the copy is refreshed. The object keeps serving the previous rows until the refresh completes.
* **View sources** are read live through the view.
* **Custom properties** stay attached to their row across refreshes. The instance key is computed from the primary key values, so a row with the same key keeps its custom values. This holds even if the source column changes from `Int32` to `Int64` or becomes `Nullable`.
* Renaming the source dataset or view re-runs the object's migration, so it follows the new name.

## Source validation

Datazone validates the source when you create the object, on every deploy, and on every migration:

* every `source_column` exists in the source,
* every `db_type` equals the column's ClickHouse type,
* the primary key has no `NULL` values,
* the primary key is unique across the source rows.

If validation fails at creation, the request returns `400` with the reason, for example `Primary key is not unique in the source: 1200 rows but 1000 distinct keys.` If the source changes later and no longer passes, the object moves to `ERROR`. Fix the source, then click **Retry** next to the object's status (or call [retry-migration](https://docs.datazone.co/reference/knowledge-objects/api.md#retry-migration)).

## History

With `store_versions` on (the default), every edit to an instance's custom properties is kept. The [history endpoint](https://docs.datazone.co/reference/knowledge-objects/api.md#instance-history) returns those edits, newest first. Each entry holds the custom properties as they were at that edit. Source fields are not versioned, so every entry shows what the source holds now. An instance that was never edited has no history.

## What you cannot change

These changes fail the deploy. Create a new object instead.

* the object type (local ↔ backed),
* the source (`settings.source`),
* the primary key.

## Next steps

* [YAML Reference](https://docs.datazone.co/reference/knowledge-objects/yaml-reference.md) — `source`, `source_column`, and relationship attributes.
* [Instance API](https://docs.datazone.co/reference/knowledge-objects/api.md) — read and update backed instances, list source columns, retry a migration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.