Relationships
Prism supports three relationship types between database models: hasMany, belongsTo, and hasOne. Define them on your models, then load related data with simple queries.Relationship Types
hasMany
A user has many posts. The foreign key lives on the related table.
belongsTo
A post belongs to a user. The foreign key lives on this table.
hasOne
A user has one profile. Like hasMany but returns a single row.
Defining Relationships
Schema
User Model with Relationships
Post Model
Loading Related Data
Has Many
Load User's Posts
Belongs To
Load Post's Author
Has One
Load User's Profile
API Example
Build an endpoint that returns users with their posts:Users with Posts API