Skip to main content

associations

Like models, serializers also have a concept of association chaining, which enables you to express rich domains without getting tied in knots

renders many

import { Attribute, DreamSerializer } from '@rvoh/dream'

export default class UserSerializer<
DataType extends User,
> extends DreamSerializer<DataType> {
@RendersMany(Pet)
public pets: Pet[]
}

RendersMany will expect an array to be present at its field. Usually, this will be done by preloading on your model before serialization, like so:

const user = await User.preload('pets').first()
this.ok(user)

renders one

import { Attribute, DreamSerializer } from '@rvoh/dream'

export default class UserSerializer<
DataType extends User,
> extends DreamSerializer<DataType> {
@RendersOne(Pet)
public pet: Pet
}