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.
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.
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.