Hi. Right now I have my data model using conditional sync using functions:
READ:
{
"%%true": {
"%function": {
"name": "canReadPartition",
"arguments": [
"%%partition"
]
}
}
}
WRITE:
{
"%%true": {
"%function": {
"name": "canWritePartition",
"arguments": [
"%%partition"
]
}
}
}
This work fine. The thing is I have now a method that creates documents in a collection called Appointment that should be able to be read by two different users. One user would be saved in storeId and the other in contactId.
Si I Tried to change the function to add a custom rule just for this collection. But it seems to break everything because I wont sync the normal partitions now:
{
"rules":{
"Appointment":[
{
"name":"appointmentUser",
"applyWhen":{
"%or":[
{
"storeId":"%%user.id"
},
{
"contactId":"%%user.id"
}
]
},
"read":{
},
"write":{
}
}
]
},
"defaultRoles":[
{
"name":"admin",
"applyWhen":{
"%%true":{
"%function":{
"arguments":[
"%%partition"
],
"name":"canReadPartition"
}
}
},
"read":{
},
"write":{
}
}
]
}
Im not sure If I can use document fields as a parameter because this is set during the session start. But If i understand correctly this is used in this example:
Type-Specific and Default Roles
{
"rules": {
"Employees": [
{
"name": "employeeWriteSelf",
"applyWhen": {},
"read": {},
"write": {
"employee_id": "%%user.id" // <==== HERE
}
}
]
},
Is this approach correct? I’ve seem someone recommend using trigger and maintain duplicated documents for each member. Is this the only way?