Ability to (mass) assign related records

How can we mass assign related records.

Expected behavior

For example let’s say we have products and categories with a many to many relationship. Now I want to be able to assign multiple products to an existing category.

Actual behavior

As far as I can see there is currently no way to mass assign related records.

Context

The way this could work is by adding a new field type for smart actions which would be able to filter a given model.

Example:

collection('product', {
  actions: [
    {
      name: 'Add to category',
      type: 'bulk',
      fields: [
        {
          field: 'category',
          type: 'Reference',
          isRequired: true,
          references: 'category.name'
        }
      ],
    },
  ],
  fields: [],
  segments: [],
});
1 Like

Hello @SvenSlijkoord :wave:

Welcome to our community :confetti_ball:

In fact this is not possible for now, sorry about that.

We plan to rework how smart action works to give our users more flexibility (such as dynamic search on records as you provided in your example).

However I can’t give you any ETA for now, sorry again.

I’m definitely pushing your feedback to my team though.

Thank you for you feedbacks, it helps a lot to improve the product :+1:

Steve.

Hi Steve,

Thank you for the quick response!

Do you know if there is a workaround we can use for the time being?

Sadly the best I can propose so far is to create a smart action (let’s say assignProductsToCategory) which would be of type bulk. The smart action should be configured with a field to enter the category name / id (not auto-completable), and then the route code would associate the products to a category (as you would be given the product ids and the category id).

Your teammates will have to handle the category id on their own, as we only provide static fields for now, but it should work.

Steve

Hi @SvenSlijkoord,

I just read this thread, I think you can achieve what you want.
Did you try, this Smart Action definition:

collection('product', {
  actions: [
    {
      name: 'Add to category',
      type: 'bulk',
      fields: [
        {
          field: 'category',
          type: 'Number', // if the category primary key is of integer type
          isRequired: true,
          reference: 'category.id' // if the category primary key is named "id"
        }
      ],
    },
  ],
  fields: [],
  segments: [],
});

It should let you select a batch of products and click the action option.

As a first step, you should see a form with a single input that should let you search for a category to assign to those products.
Once the action triggered, if the Smart Action controller is properly implemented, it should attach the products to this category.

Let me know if it does not help :pray:

Thank you! This works perfectly

1 Like