atk4 / data

Data Access PHP Framework for SQL & high-latency databases
https://atk4-data.readthedocs.io
MIT License
273 stars 46 forks source link

Implement lazy joins and Lazy fields #118

Open romaninsh opened 8 years ago

romaninsh commented 8 years ago

Lazy Fields and Lazy Joins are those optional fields that will not be loaded unless requested. The logic should be like this:

Adding a lazyJoin will make it's field lazy too. If you have not requested any of the "lazy" fields from the join, then join won't be performed either.


As suggested on reddit - we should make our 'leftJoin' optional.

adding leftJoin does not impact the scope of the model. So if no fields have been selected (through onlyFields) from the joined table, then there is no need to join it. This can be a good optimisation if we:

romaninsh commented 7 years ago

see #208,.

romaninsh commented 6 years ago

Suggested syntax:

$model->addExpression('bleh', ['..complex formula', 'lazy'=>true]);
$model->addField('blob', ['lazy'=>true']);

Unlike system property which makes fields selected by default (even if onlyFields in effect) lazy will avoid selecting fields unless they are specifically requested by onlyFields.

A difference to onlyFields would be if lazy field is accessed:

$model->load(1);
echo $model['blob'];

Then model would specifically load the field. In most cases this is a reasonable trade off for a lazy field. This mechanic will NOT work for fields that are omitted by onlyFields, because otherwise this can cause sigificant application slow-down when accessing a field, which ought to be system.

romaninsh commented 6 years ago

Use case: password field could be lazy, because we don't like loading passwords.

mvorisek commented 2 years ago

very simillar feature request: https://github.com/atk4/data/issues/319

mvorisek commented 8 months ago

related with https://github.com/atk4/data/issues/1093