Query `include` doesn't trigger `beforeFind` trigger for included objects

Hello,

When I was testing parse server I’ve found that, beforeFind trigger is not triggered for included objects in find or get queries using include option.

Is this working as expected?

We’re applying custom ACLs in beforeFInd trigger. Without beforeFind triggers for included objects we’re not able to apply ACLs on included objects.

If this is intentional, could you please help me with alternative solution?

Could you please give an example and/or share some code?

Thanks for the reply. Here’s an example

Client Side code:

const company = new Parse.Object('Company');
company.id = 'company_id';

const query = new Parse.Query('Employee');
query.equalTo('company', company);
query.include('user'); // user is an instance of _User
const results = await query.find()

Cloud Code

Parse.beforeFind('_User', (req) => {
  // This is triggered for Employee class but not for _User class, when above query is executed
  
  // custom acl code using casbin library. Parse ACL is set to public read/write on all classes
})

Please let me know if more information is needed.

I’ve just checked the code and unfortunately beforeFind trigger when not fire in this case for the include query. Basically the trigger is called one layer over (parse-server/rest.js at 9ea355b4635226ae4da17c8cc5fb0321e3fdec5e · parse-community/parse-server · GitHub) the one that is internally used to run the query to include the sub objects (parse-server/RestQuery.js at master · parse-community/parse-server · GitHub). An workaround could be handling this on beforeFind or afterFind trigger of the Employee class.