Skip to content

Use PropSchemas inside of custom PropSchema functions #176

@earlAchromatic

Description

@earlAchromatic

I am trying to serialize a Set (using custom propSchema like in #157), but would like the result to use a reference inside the custom PropSchema to point to objects in the Set.

This doesn't work though:

import {identifier, reference, createModelSchema} from 'serializr'
// transmitters is a Set
// Transmitter is the class of each Set item

createModelSchema(Receiver, {
  id: identifier(),
// Want this to be a list of refs
  transmitters: custom((model) => {
    const array = Array.from(model)
    return array.map(() => {
      return reference(Transmitter)
    })
  }, deserializer)
})

Is there a way to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions