Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

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.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.