Backendless Support
 
Answered

How to hide fields from relation retrieve

Some time ago I saked this question http://support.backendless.com/topic/how-to-retrieve-objects-not-with-all-fields and it's work perfectly, but today I met a new complication. When I retrieve object which contains relationship to other database, afterFind event handler doesn't work.

For example: I have this table and I retrieve all of this items via REST API (Pay attention: autoload is on) and I want to hide "email" field from Users table

Memes table:

e091b602f59bd18a838c06e2881d9297

All objects have a relationship with Users table.

User table:

999490c0dd55400b8d4a82fe71249592

And this event handler (After find from Users table) does not work!

bb733d06375c5cb8b4b6cced454b6424

So, why it isn't working?

Now I see only one solution: make an another after find event for Memes table, but there is a big reason to not to do this: When I'll have any other relations with Users table I should make a afterFind event for all of this relations, and this handlers will take my Script Running Time and I'll should pay for this

Best Answer
photo

When you retrieve data from the Memes table, even if it includes autoload properties, only the handler for that (Memes) table will be triggered. This means all the logic for filtering out the fields from the related properties must also be inside of that handler.

The logic that would work goes like this:

  1. Iterate over the Memes objects in the response.
  2. For each Memes object, get the "author" property and assign it to a variable (say "userObj")
  3. Delete the "email" property in the "userObj" variable.

Hope this helps.

Mark

Leave a Comment

Comments (4)

photo
1

Hi timuruktus

The event handler is not being triggered because its context is Users table. It's triggered when you execute 'search' in Users table. So when you execute 'find' to Memes table - handler shall not be triggered even if there's a relation between Memes and Users.

Regards Anton

photo
1

Thanks, but the question is: how can I hide a properties of objects, which retrieved from relationships?

photo
2

You also asked why your handler is not working, and my response was an answer to the question. As far as I know the solution you suggested is the only option of how you can 'hide' unnecessary fields in response (creating additional handler). I will think of another workaround and get back to you ASAP

photo
photo
2

When you retrieve data from the Memes table, even if it includes autoload properties, only the handler for that (Memes) table will be triggered. This means all the logic for filtering out the fields from the related properties must also be inside of that handler.

The logic that would work goes like this:

  1. Iterate over the Memes objects in the response.
  2. For each Memes object, get the "author" property and assign it to a variable (say "userObj")
  3. Delete the "email" property in the "userObj" variable.

Hope this helps.

Mark