data icon indicating copy to clipboard operation
data copied to clipboard

Refactor Model::getFields

Open georgehristov opened this issue 4 years ago • 5 comments

  • Introduce constants to declare Model field filter presets
  • Adds Model::FIELD_FILTER_PERSIST filter preset
  • Adds Model::FIELD_FILTER_ONLY_FIELDS filter preset
  • uses new presets to remove duplicate code
  • Provide the possibility to filter fields by Closure

georgehristov avatar Aug 05 '20 14:08 georgehristov

Provides possibility to filter fields by Closure

I do not get this - we should get all and filter then, what is the advantage of your approach?

mvorisek avatar Aug 05 '20 14:08 mvorisek

This is also true. Main point was to introduce the 'persisting' preset to avoid duplicate code. And streamline the code a bit with the ifs and buts. Passing a Closure as filter is a side-effect

georgehristov avatar Aug 05 '20 15:08 georgehristov

I have another idea: Presently filters are in first argument as array and considered OR.

We can introduce multiple arguments which will be filters merged with AND.

So $model->getFields('system', 'only_fields') will return fields system AND only fields So $model->getFields(['system', 'only_fields']) will return fields system OR only fields

It will not be BC though I believe.

georgehristov avatar Aug 18 '20 10:08 georgehristov

I have another idea: Presently filters are in first argument as array and considered OR.

I like minimalistic APIs. We extend Model more and more for BC... And the questions is what this more and more code provides? Does it really help and reduce the maintanence requirements? If yes, go ahead!

mvorisek avatar Aug 18 '20 10:08 mvorisek

TODO rebase on develop, it is based on https://github.com/atk4/data/pull/690, only the last 10 commits are relevant (others are from the mentioned PR) - https://github.com/atk4/data/compare/be3cb50a37...d6307b30c3

mvorisek avatar Sep 07 '23 14:09 mvorisek