Skip to content

Detect if a field was hidden in afterInit event #724

@dnish

Description

@dnish

Hey,
I'm currently adding some data in my afterInit event. It currently looks like this:

Posting.js

afterInit(e) {
  const doc = e.currentTarget;
  doc.userDoc = User.findOne({_id: doc.userId});
}

Because of some performance improvements, I want to disable the loading of the user document. I know that I can disable events via options, but there may be some other code, which still should run. So I want to create a query like this:

Posting.findOne({},{fields:{userDoc:0}});

Now the problem happens: I'm not able to get the options parameter within the afterInit event, so I'm not able to detect if I had disabled the field. After reading the documentation, I found out, that the afterFind event could help. Because it also returns the result, I could add the userDoc object if it wasn't disabled in the options. That works fine if I do a findOne(), but will fail if I do a find().fetch(), because in this case, result returns a MongoCursor instead of the result array.

So, what would be the best way to attach additional data depending on the options?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions