-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array field in PostgreSQL return ArrayExpression instead of array #15716
Comments
Thank you for opening this issue. On the first iterations of Arrays support, the AR model's fields got arrays after data population. From some point of discussions, we've decided to create We already have two unexpected behaviors related to this decision. See #15710 @yiisoft/core-developers |
Yes, I already discovered two issues with this approach. And I think there might be much more. |
This is the matter of lazy loading. Having large JSON or ARRAY data may provide significant impact while being parsing over hunderds of records fetched from DB. Also not every complex DB type can be converted to an array. For example, while using PostGis extension, its specific type 'geometry' can not be represented as mere array - it should be a specific complex object. Still, this matter is debatable. |
Great feature, but I think ArrayExpression is not a PATCH update, because it broke a lot of model getters, used before for Postgres array fields. |
It was not a PATCH update indeed. We have Semver shifted on one group to the right: @zhdanovartur what is the best solution on your opinion? We are thinking about adding a flag for Schema class, that allows to return array instead of ArrayExpression, or to return string as it was used before. |
It would make sense. But for now it parsed on phpTypecast. So it always parsing, no matter need or not. If we talk about consistency, then the json fields are now returned as an array, not JsonExpresson, but array fileds returned as ArrayExpression. It looks strange to me.
Flag is looking good to me. Unexpected ArrayExpression broke some code in my projects. |
Laziness can be easily added afterwards and nobody will notice the change ;)
But yes, that does not look very consistent, so it is a point of discussion now.
Could you check, whether it is any better with fix in #15733? |
Good idea. |
It not work for in_array It's not hard for me to fix my code, but for backwards compatibility (if needed), I think the flag is the only option |
Added flag in #15755 Can be configured somehow like this: 'db' => [
'class' => \yii\db\Connection::class,
'schemaMap' => [
'pgsql' => [
'class' => \yii\db\pgsql\Schema::class,
'columnSchemaClass' => [
'class' => \yii\db\pgsql\ColumnSchema::class,
'disableJsonSupport' => true,
'disableArraySupport' => true,
'deserializeArrayColumnToArrayExpression' => false,
],
],
],
], Or easier: [
'container' => [
'definitions' => [
\yii\db\pgsql\ColumnSchema::class => [
'class' => \yii\db\pgsql\ColumnSchema::class,
'disableJsonSupport' => true,
],
],
],
] @tQuant Could you check with code from new PR and an appropriate config? |
Fixed by 25d176a |
Does anybody tested this fix in FULL reality? |
We've spent days to fix our system and about day to figure out why this approach described here don't work year and half ago. Without result. We neded to move on now so my colegue now tried this again... after long debug of how all this work we finally found out basic reason why it won't work... So, if this does'nt work, flush the cache to change values and reread config. |
There is no point to return ArrayExpression for array fields when loading ActiveRecord from database.
ArrayExpression do not have any usefull information per value. Data type and dimension can be obtained from the table scheme.
What steps will reproduce the problem?
Create an array postgresql field. Create ActiveRecord model. Load model from database.
What is the expected result?
Field contain array
What do you get instead?
Field contain ArrayExpression
Additional info
The text was updated successfully, but these errors were encountered: