yii2-multiple-input icon indicating copy to clipboard operation
yii2-multiple-input copied to clipboard

How to work with ActiveRecord models?

Open kwazaro opened this issue 6 years ago • 5 comments

How to automatically save data to database and read it for widget using ActiveRecord models? No information or examples provided, only examples with \yii\base\Model. Maybe, some Trait should be created, to convert data to JSON and back to PHP array? It is not good idea to edit controllers. I think data conversion should be done by this extension automatically, because without this using of extension is not convenient.

kwazaro avatar Jul 18 '19 19:07 kwazaro

Should I use the JSON column database type for fields? Also, I noticed, that 'sortable' has some strange behavior when using JSON database column type: it doesn't change row indexes after sorting, so after saving the result has no effect (the order is based on row numeric "keys", they don't changing after sorting).

kwazaro avatar Jul 19 '19 09:07 kwazaro

did you read the article https://github.com/unclead/yii2-multiple-input/wiki/Basic-scenario-of-usage ? I don't agree that the widget has to be responsible for server-side processing, because it doesn't know anything about your business logic.

Originally it was created only to provide a simple way to manage similar data such as email/phones without the necessity to reinvent the wheel each time. But the widget has evolved a lot since its first release and it contains many features now.

If you want to implement a trait or a yii behavior to simplify processing data on server-side, PR is always welcome

unclead avatar Jul 20 '19 17:07 unclead

And what about JSON type in database column? Sortable not working in this case, because of fixed array indexes. JSON type is preferable for such data.

kwazaro avatar Jul 21 '19 04:07 kwazaro

@kwazaro still relevant or I can close the issue?

unclead avatar Jan 08 '21 11:01 unclead

You should mention in description that this component doesn't support sorting for JSON fields. There is no solution for now.

kwazaro avatar Jan 08 '21 20:01 kwazaro