Skip to content
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

Model: excludeFields() function would be nice #319

Closed
PhilippGrashoff opened this issue Apr 17, 2018 · 5 comments
Closed

Model: excludeFields() function would be nice #319

PhilippGrashoff opened this issue Apr 17, 2018 · 5 comments

Comments

@PhilippGrashoff
Copy link
Contributor

Hi,
at the moment there is the possibility to define onlyFields, and only these fields will be loaded.
The ability to do the reverse, to exclude some fields, would be great:

  1. Imagine you have a model with 50 fields and you want to exclude 2 for some reason. That makes quite a long onlyFields parameter :)

  2. Same case again, but in future the model may get additional fields. Now excluding the 2 fields via onlyFields() may lead to failures in future, as onlyFields was used with the intention to only exclude these 2 fields - it will also exclude any newly added field of the model if onlyFields code is not altered.

@romaninsh
Copy link
Member

This is very similar to #118

@mvorisek
Copy link
Member

@georgehristov you mean exclude some model fields or exclude one field from the database dable (eg. query database for all available field first)?

@DarkSide666
Copy link
Member

DarkSide666 commented Aug 26, 2021

onlyFields means that only these fields will be included in DB query (plus system ones of course).
excludeFields means that all fields will be included in DB query except these few ones.

Field names are taken from data Model not actual DB table fields.

Issue can arise if we use both these functions at the same time - onlyFields() and excludeFields(). These can clash then so we have to define priority of these. But idea as such is good.

Usage example - we never want user to load password field from database, so why not just $model->excludeFields(['password']) and we're safe.

Another example - model can contain some fields which include complex select logic from nested tables which works slow on load. If we don't need to load this field always, then we can exclude this field from load (like lazy loading of some kind).

@mvorisek
Copy link
Member

Field names are taken from data Model not actual DB table fields.

fine, can be useful

Issue can arise if we use both these functions at the same time - onlyFields() and excludeFields(). These can clash then so we have to define priority of these. But idea as such is good.

that should result in an exception

@mvorisek
Copy link
Member

closing in favor of #118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants