Skip to main content
Using UBRef allows you to easily save relational data without knowing foreign key IDs in advance.

Relationship Patterns Overview

OneToOne

1:1 relationship User → Employee

OneToMany

1:N relationship Department → Employees

ManyToMany

N:M relationship Projects ↔ Employees

Hierarchical

Self-referencing Department → Parent

OneToOne Relationship

When User and Employee have a 1:1 relationship:

OneToMany Relationship

When Department has multiple Employees:

ManyToMany Relationship

When Project and Employee have N:M relationship (using junction table):
ManyToMany Save Order: 1. Save both main tables first (projects, employees) 2. Save junction table later (projects__employees)

Hierarchical Structure (Self-Referencing)

When Department references a parent Department:
Result Structure:
Self-referencing refers to the same table, so it can be saved with one ubUpsert. However, circular references are not possible.

Complex Relationships

Company → Department → Employee → User full chain:

Practical Examples

Create Project (Team Assignment)

Create Organization Structure

User Invitation (User + Profile + Settings)

UBRef vs Actual ID

Using UBRef (New Records)

Using Actual ID (Existing Records)

Mixed Usage

Next Steps

Batch Operations

Bulk data registration

Advanced Patterns

Complex data structures

Basic Usage

UpsertBuilder basics

Transactions

Transaction guide