data icon indicating copy to clipboard operation
data copied to clipboard

Implement lazy joins and Lazy fields

Open romaninsh opened this issue 8 years ago • 5 comments

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

  • without onlyFields() - load all fields except lazy
  • with onlyFields() - load requested fields and system fields

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:

  • remove "system" from our_field field.
  • add field into onlyFields if any fields required by joins are requested
  • add our_field if join requires it and if it's located in a join, add that one also
  • do so recursively

romaninsh avatar Aug 25 '16 11:08 romaninsh

see #208,.

romaninsh avatar Dec 05 '16 13:12 romaninsh

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 avatar Mar 09 '18 15:03 romaninsh

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

romaninsh avatar Mar 09 '18 15:03 romaninsh

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

mvorisek avatar May 29 '22 11:05 mvorisek

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

mvorisek avatar Feb 21 '24 10:02 mvorisek