✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

In Sanity Studio, I have Posts and I have People. Each Post references one or more People. At the time of a Post, People have certain jobs and those are included in the Post...

5 replies
Last updated: Nov 30, 2020
In Sanity Studio, I have Posts and I have People. Each Post references one or more People. At the time of a Post, People have certain jobs and those are included in the Post as a People reference. If someone's job later changes, I don't want the content in each Post to update with it. I'd appreciate guidance about where I should I be looking to implement this sort of thing. Thanks!
Nov 29, 2020, 6:49 AM
Post refer to Jobs(At the time of a Post).Jobs refer to people.
People refer to Jobs(current).

You will have to make one customization which I don't think is available in sanity by default. So that, at the time of creating the post. The references to Jobs for a person are saved.
Nov 29, 2020, 8:43 AM
Perhaps each person can have a reference to an array of Objects representing jobs held. Then a job can have a
start
and
end
date that can be used to switch out based on some other logic. Like a post date.
Sounds like a content modeling wrangle-up!
Nov 29, 2020, 10:09 PM
You could also make
{
  name: 'postAuthor',
  type: 'object',
  fields: [
{ name: 'person', type: 'reference', to: [{type: 'person'}]},
{ name: 'jobTitle', type: 'string' }
  ]
}
In the
Post
type, and then make a custom input component that fetched the person’s job title and set the string field to that value. Here's some code that can be adapted. https://github.com/sanity-io/sanity-recipes/blob/master/snippets/stringInputWithValuesFromAnotherDocument.js
Nov 30, 2020, 12:47 PM
Or do it with a custom document action! Like, when you push publish, go to the referenced Person document and set the job title to the post document. https://www.sanity.io/docs/document-actions
Nov 30, 2020, 12:48 PM
user C
,
user B
, and
user Y
: Thank you all very much for the advice!
Nov 30, 2020, 3:46 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?