Select exists objects and create new from Select2 widget in Symfony

I came from Yii2 world, where i often use this pattern: if one model has related many-to-many simple models like tags, music genres etc., I use a Select2 widget with “multiple=true” and “tags=true” option. And on a backend side i usually have a model creator or updater class, witch i call from controller and pass data array to it. This class parse data from request object and if tag value !is_numeric, try to find and then create and store a new tag object. Then the r string value replaced with new created object id. After this, form data loads to model with only integer values in tag field and validates fine.

I want to understand, what is the proper way to do something like this in symfony. On what abstraction levels i should do this and how. I cant find any examples of this pattern.

In other words: where and how in symfony standard flow i should detect a non numeric values and replace it with id of new object.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *