Update a relation "has many" array with controller

Hello, I use Strapi V4. I have a link collection and I want to update likes.
How update the relation array ? When I put new data old value are replace by the new one.

Example :
likes : [1]
if I update another time
likes:[2].
BUT I want this likes : [1,2]

I try this but It d’oesn’t work. Thans for your replay

'use strict';

/**
 *  link controller
 */

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::link.link', ({ strapi }) => ({
    // Method 2: Wrapping a core action (leaves core logic in place)
  async find(ctx) {
    
    const { data, meta } = await super.find(ctx);
    const linkId = data.map((link) => link.id);

    const allPosts = await strapi.entityService.findMany('api::link.link', {
      fields: ["id"],
      filters: { id: { $in: linkId } },
      populate: {
        likes: { count: true },
      },
  });

    data.forEach(link => {
      link.likes = allPosts.find(({ id }) => id === link.id)?.likes?.count || 0;
    });

//update value with new array => need to be fix
     await strapi.entityService.update("api::link.link", {
       likes: [...allPosts.likes.map(({ id }) => id), ...likes],
     });

    return { data, meta };
  },
}));
1 Like

More details
Relation type is Link belongs to many Likes

Have the same issue by updating has many relations. I recieve the error like:
SqliteError: insert into 'mailing_groups_contacts_links ... 3109 as 'recipient_id' returning 'id' - too many terms in compound SELECT

Here is my case:

    await strapi.entityService.implementation.update(
      'api::mailing-group.mailing-group',
      groupId,
      {
        data: {
          contacts: [...thisMailGroup.contacts, newContact],
        },
      }
    )

frontcodelover, did you solve this problem for you?