Child Object Permissions

cloud

#1

In another thread there is this quote:

Below is a pseudo schema and setup:

Booking:
  _id: string
  job: {type: 'linkingObjects', objectType: 'Job', property: 'bookings'},
Job: 
  bookings: 'Booking[]'
  permissions: '__Permission[]'

And let’s say I’ve created a job with the following attributes:

...
//create job1 etc. 
...
job.permissions = {
  role: {name: '__User:user1'},
  canRead: true,
  canUpdate: true,
  canDelete: true,
  canSetPermissions: true,
  canQuery: true,
  canCreate: true,
  canModify: true,
}
job.bookings = [{_id: 'booking1'}, {_id: 'booking2'}]

If I do the following as user1, I will get a list of jobs and their associated bookings. Which is great, fine, all understood. That matches what is said in the quote above.

let jobs = realm.objects('Job')
jobs.subscribe()
console.log(jobs.bookings.length) //===2

However, I want to generate a list of bookings as such.

booking1, job1
booking2, job1

if I want to get a list of bookings like this, it wont return the bookings as there aren’t any permissions on the object. This also makes sense.

let bookings = realm.objects('Booking')
bookings.subscribe()
console.log(bookings.length) //===0

So, my question is, how can I do it? The way I see it there are few potential ways of doing it, but I’m not sure if they are even possible or not.

  1. Group a jobs result by booking. But I can’t find any documentation regarding grouping. Something like this…
let jobs = realm.objects('Job').groupedBy('bookings._id')
  1. Query the jobs, then extract the bookings to build the result set (messy)

  2. Apply the same permissions to all of the Job’s child objects. The problem with this is it is very laborious and prone to errors, inconstancies and corruption. Especially as some of my child objects have children of their own etc.

  3. Hopefully you kind people will have a great response?