-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Database: removed refetching all columns on ActiveRow::toArray() (BC break!) #1010
Conversation
👍 |
I am not sure this is good. Consider the unexpected behaviour of toArray(). Solution is update cache to fetch all columns next time. |
@dg For me it's the current behaviour that is unexpected. |
@dg well, yes I considered it a lot. If I call $row->toArray() I expect to get array of feteched column in row. Also the fact some queries need all columns is nonsence. They don't need it, they just don't know what they need - it's quite opposite what this feature should bring. The toArray is pattern and refetching for all columns (in background of this method) is magic which I want to get rid of. |
@dg After another day of thinking I am sure this is right. Changing strucutre can't fetch another data, it's just wrong. Only use case which came on my mind is geting data for session and then transforming to array... and that's exactly the case, when you should explicitly use |
@enumag: Unexpected? Now it returns table row as array. Always the same array. With this commit, it returns some fields, nobody knows which ones. |
@hrach: Caching is transparent mechanism for accelerating of application. Function toArray() must return the same result whether caching is enabled or not. Otherwise it's behavior is unexpected. |
@enumag this is bug, but this commit is not solution. |
Main reason:
Comment to @dg arguments:
No, wrong.
Not exactly true. After this commits it returns just that what IRow contains. Not satisfied with this? Let Selection to fill Row with all columns.
Of course, yes, but that's all about understanding the meaning of ActiveRow and feature, which provides. The feature (to refetch needed columns) provides ActiveRow, not array. Some problems connected with this magic: $a = $db->table('author')->fetch();
unset($a->author);
$a->toArray()
$a = $db->table('author')->fetch();
$a->fullname = $a->firstname . $a->lastname;
$a->toArray();
etc. etc. etc. |
@hrach please, do not fuck. I'll try explain why this commit is totally fucking wrong. Delete cache in CD-collection example and sign in. The identity will contain 'username' field. Then sign out and sign in again. The 'username' field disappears. Oh fuck! Yes, it can be fixed by adding |
@dg: Username is used for authentication which means it will be accessed and therefore will be in the array. What you said is correct for firstname and lastname. |
@enumag try it |
@dg srry it's used in where, you are correct |
What about inventing another method, something like |
However in my opinion the toArray method should not be used in this case. It'd be better to create the array manually with only needed data, not everything that might be in the table. You may also need to add some data from other tables. @vojtech-dobes there is no need in my opinion, we have |
ad unset(): I do not really like this ActiveRecord stuff. It would be better if properties were read-only and ActiveRow::$modified did not exist. |
Please, provide someone real usecase which
I do not know any of this usage. Your provided example is bad! You just do it wrong. You know you need all columns, you shall use explicit |
Default option is "all columns". |
Well, I agree with you. I would removed it. But it would lead only to overusing toArray(). Not sure what to do with it. Maybe would be correct to do not allow new columns and do not allow unset them.
What about new API, which would enable this magic. Such as |
Autoselect is default too ;-) I think current behavior is correct, the only problem is with cache. Cache should remember that we need all columns and avoid sending two database queries next time. The fact that toArray() disables some acceleration mechanisms should be mentioned in documentation. „If you'd like to use toArray(), consider using select(...) method, otherwise all columns will be transfered.“ |
There is still problem with unset. |
Unset & modify is common problem, not just toArray problem.
|
Yes, but toArray is the most common situation, when it happens. What about allowing toArray only when there is a explicit select? |
Removed some magic ported from NotORM.
Some discussion: http://forum.nette.org/cs/13703-mozna-chyba-v-cachovani-sloupcu-u-dotazu-v-nette-database
Correct workaroudn is to use
->select('*')
to get all columns. Othrwise in current state is impossible to iterate only over fetched columns.