I'm trying to use a custom attribute in a model class that extends db\activerecord.
I've tried declaring public $categories = [] and then either assigning values to it directly via $model->categories = [1,2,3] or using a setter method in my model class public function setCategories($ids) {... and then again assigning via $model->categories = [1,2,3].
I've also tried updating the attribute with $model->setAttribute('categories', [1,2,3]).
In all cases $model->categories is not populated.
My end goal is to assign categories to a model and then update the db relation/tables using afterSave() and beforeSave()
Can this be done or should I extend my model class from db\model? If I do, what functionality will I lose?
Edit I might have misstated my problem.
I've got a form where a user can select categories for a specific model (ie "Product"). All categories are pre-existing and products are assigned to categories via a junction table product_category('product_id', 'category_id') with a one-to-many relationship (one product has many categories).
Now in the controller that's handling the view, I'm receiving a list of category id's and I want to assign them to an attribute so that I can process them i.e. delete or add (via link()) entries in the product_category table for the specific product.