We should consider mysql json additional to Yii2 model

Since the introduction of JSON as a column type in Mysql, this has emerged as a useful tool to store structured data without having to create separate tables reducing the need for joins and related tables.

One problem is the lack of support for JSON in the Yii model which is missing from most frameworks at the moment, which I feel we can introduce including.

a) 1-touch updates.

$row->someColumn->key = ‘somedata’

Automatically defining a ‘someColumn’ as Json allow access to the child.

b) ActiveRecord find including JSON

Find()->whereJSON(‘column’,‘key’,‘value’)
This will run JSON filters in SQL

c) Wildcare key searchs for JSON key.

The current sql syntax for JSON search isn’t very good and I think we can improve the functionality through our Model.

4 Likes

u can write your own Behavior to implement A) and ActiveQuery for B) and C)

1 Like