General question, but what is the difference betwe...

default discord avatar
Payload-Bot
last month
4

General question, but what is the difference between setting an array and a "hasMany: true"?



Original message from @shisue - Moved from https://discord.com/channels/967097582721572934/967097582721572937/1143198503015813180 (in #general)
  • discord user avatar
    alessiogr
    Payload Team
    last month

    @shisue do you mean hasMany: true on the number field?

  • default discord avatar
    shisue
    last month

    Yea, something like:



    {


    name: 'projects',


    label: 'Projects',


    type: 'relationship',


    relationTo: 'projects',


    hasMany: true,


    }



    vs



    {


    name: 'projects',


    label: 'Projects',


    type: 'array',


    ...


    }



    Is array just a way of having fields that have different types (polymorphic), while hasMany:true will make an array regardless, but of a single type?

  • discord user avatar
    alessiogr
    Payload Team
    last month

    Nope! Relationships can be polymorphic as well!



    The difference is that for the array, the project would be saved IN that array field. Like, it's part of the document.



    For the hasMany relationship, the project would be saved in another document in the projects collection

  • default discord avatar
    shisue
    last month

    I see, that makes sense! So, does that affect query time? Let's say I have organizations, which has many projects. If I want to store it as "hasMany" and query organizations, how would that query work?

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.