Skip to content

If it is possible to fetch some particular field all the time #14074

Discussion options

You must be logged in to vote

I don't think scopes would work here because setting the attributes option field would override the one from the scope but you should be able to achieve what you're trying to do using the beforeFind hook: It'll receive the options and you can add the attributes you want to them.

I think it would look like this, but this code hasn't been tested:

YourModel.beforeFind((options) => {
  if (Array.isArray(options.attributes) && !options.attributes.includes('email')) {
    options.attributes = [...options.attributes, 'email'];
  }
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ephys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #14072 on February 09, 2022 07:52.