CMS Relationships
Brightsy AI CMS supports defining relationships between record types using has-one and has-many relationship fields. These allow you to create structured data models with foreign key relationships.
Relationship Types
Has-One Relationships
A has-one relationship allows a record to reference a single record from another record type.
Example: Blog Post with Author
{
"type": "object",
"required": ["title", "content"],
"properties": {
"title": {
"type": "string",
"title": "Title"
},
"content": {
"type": "string",
"format": "textarea",
"title": "Content"
},
"author": {
"type": "object",
"format": "has-one",
"title": "Author",
"properties": {
"relationship": {
"type": "string",
"default": "has-one"
},
"contentType": {
"type": "string",
"default": "authors"
},
"id": {
"type": "string",
"title": "Author ID"
}
},
"required": ["id"]
}
}
}
The has-one relationship will:
- Display a dropdown selector with available records from the related record type
- Show a "View related record" link when a record is selected
- In data tables, automatically fetch and display the related record's label
- Store the relationship as:
{ relationship: "has-one", contentType: "authors", id: "record-id" }
Has-Many Relationships
A has-many relationship displays all records from another record type that reference the current record via a foreign key field.
Example: Author with Blog Posts
First, create an "authors" record type. Then create a "blog-posts" record type with a foreign key:
{
"type": "object",
"required": ["title", "author_id"],
"properties": {
"title": {
"type": "string",
"title": "Title"
},
"author_id": {
"type": "string",
"title": "Author ID"
},
"content": {
"type": "string",
"format": "textarea",
"title": "Content"
}
}
}
Then, add a has-many field to the "authors" record type:
{
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"email": {
"type": "string",
"format": "email",
"title": "Email"
},
"posts": {
"type": "object",
"format": "has-many",
"title": "Blog Posts",
"properties": {
"relationship": {
"type": "string",
"default": "has-many"
},
"contentType": {
"type": "string",
"default": "blog-posts"
},
"foreignKey": {
"type": "string",
"default": "author_id"
}
}
}
}
}