Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

735
Visualizações
strapi v4: How to create a Entry with Relation?

When I create a new entry in my Collection-Type all of the values for the fields get added to the newly created entry EXCEPT for the value for the field with the Relation type.

So for example in my event Collection-Type I have name, performers, venue, address, date, time, description and user

user is a Relation type (Relation with User (from:users-permission))

The rest are either Text, DateTime, RichText, etc.

after I get the data from the form I end up having a object similar to:

var values = {
        name: 'namevalue',
        performers: 'whatever',
        venue: 'whatever',
        address: 'xyz address',
        date: '2022-12-15',
        time: '10:00 PM',
        description: 'Description of the Event',
    }

I then just edit the values object above to get the final version of value as

var values = {
            name: 'namevalue',
            performers: 'whatever',
            venue: 'whatever',
            address: 'xyz address',
            date: '2022-12-15',
            time: '10:00 PM',
            description: 'Description of the Event',
            user:1
        }

PLEASE TAKE NOTE OF the user:1 added to the object above

However after submitting the above values to the correct endpoint:

const res = await fetch(`${API_URL}/api/events`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                Authorization: `Bearer ${token}`,
            },
            body: JSON.stringify({
                data: values,
            }),
        })

In the Strapi backend the user field and value totally does not show up.... For example this is what I get:

{
  data: {
    name: '13',
    performers: '13',
    venue: '13',
    address: '13',
    date: '2022-06-10',
    time: '8:00 PM',
    description: '13'
  },
  files: undefined
}

As you can see the rest of the data I get and it then gets added to the newly created Entry but WITHOUT the Relation value that I need and want.

What am I doing wrong and how to fix this????

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda