I am trying to use a custom attribute in a model class that extends db\activerecord.
I tried to declare public $categories = [], and then assigned values to it directly through $model->categories = [1,2,3]or using the setter method in my model class public function setCategories($ids) {..., and then assigning through again $model->categories = [1,2,3].
I also tried updating the attribute with $model->setAttribute('categories', [1,2,3]).
In all cases $model->categoriesit is not filled.
My ultimate goal is to categorize the model and then update the db relation / tables with afterSave()andbeforeSave()
Can this be done, or should I extend the model class from db\model? If so, what functionality will I lose?
Edit
Perhaps I was mistaken in my problem.
I have a form where the user can select categories for a specific model (for example, "Product"). All categories already exist, and products are assigned to categories through the product_category connection table ('product_id', 'category_id') with a one-to-many relationship (one product has many categories).
Now, in the controller processing the view, I get a list of category identifiers, and I want to assign them to an attribute so that I can handle them, i.e. delete or add (via link()) entries in the product_category table for a specific product.