githubEdit

Node

The node type represents references (links) to other database records, enabling relationships between entities.

Overview

Property
Value

Go Type

*OtherNode (pointer to another Node type)

Database Schema

option<record<table_name>>

CBOR Encoding

Direct (as record ID)

Sortable

No (use nested field sorting)

Definition

Node references are always pointers to other Node types:

type Post struct {
    som.Node

    Title   string
    Content string
    Author  *User     // Reference to User
    Editor  *User     // Another reference
}

type Comment struct {
    som.Node

    Text   string
    Author *User  // Reference to User
    Post   *Post  // Reference to Post
}

Schema

Generated SurrealDB schema:

Creating Node References

Filter Operations

ID-Based Filtering

Nested Field Filtering

Access fields of the referenced record:

Deep Nesting

For deeply nested references:

Nil Checks

Sorting

Node fields themselves are not sortable, but nested fields are:

Fetching References

Use Fetch to eager-load referenced records:

Multiple Fetches

Nested Fetches

Common Patterns

Filter by Author

Filter by Author's Property

Posts Without Editor

Self-Reference (e.g., Parent)

Complete Example

Filter Reference Table

Operation
Description
Returns

ID()

Access record ID

ID filter

<FieldName>

Access nested field

Field's filter type

IsNil()

Reference is null

Bool filter

IsNotNil()

Reference is not null

Bool filter

ID Filter Operations

Operation
Description
Returns

Equal(id)

ID equals

Bool filter

NotEqual(id)

ID not equals

Bool filter

In(ids...)

ID in set

Bool filter

NotIn(ids...)

ID not in set

Bool filter

Nested Field Access

All fields of the referenced node type are accessible:

Last updated