How can I fill the extra columns of the pivot table when adding a record?

I know how to do this using Eloquent, but I’m struggling to figure out how to achieve it using .yaml files in OctoberCMS. Could you guide me in the right direction?

What I’m trying to do is use the articles relationship I added to the users plugin on the backend user update page. When adding an article, there are several inputs that are not used in the articles table but should be included in the pivot table. I want to fill these inputs when adding an article and ensure that these data points are added to the user_article pivot relationship when the article data is saved.

Can you help me with this?

// Article relations ( UserModel::extend(…) )
$model->belongsToMany[‘articles’] = [
Article::class,
‘table’ => ‘foo_plugin_user_article’,
‘key’ => ‘user_id’,
‘otherKey’ => ‘article_id’,
‘pivot’ => [‘article_author_order’, ‘user_article_field’, ‘user_article_subfield’]
];

// config_relation.yaml
articles:
label: “Articles”
view:
list: $/foo/plugin/models/article/columns.yaml
toolbarButtons: add|remove|create|delete
manage:
list: $/foo/plugin/models/article/columns.yaml
form: $/foo/plugin/models/article/fields.yaml

Hi @hackus ,

Please see this section:

You can also download the test-plugin and see how it’s done : GitHub - octobercms/test-plugin: Test Suite & Playground for October CMS

There must be a way to solve this, but despite adding a few details to the .yaml configurations, I couldn’t find it. I can’t figure out what I’m missing, and despite glance the october-test plugin, I haven’t found a solution.

For now, I’m handling my tasks by defining an afterSave function in the articles model. To update the data, I added pivot form fields to the config_relation.yaml. This way, when a user clicks on any article listed on the update page, they can update the pivot fields.