Rules to avoid repeated data on Firebase -


i need create validation rule in firebase don't have repeated data primary key in relational db. here code trying:

"roles": {         ".read": "auth.uid != null",         "$rol_id": {           ".write": "auth.uid != null",           ".validate": "newdata.haschildren(['description', 'state'])",           "description": {             ".validate": "newdata.isstring() &&              newdata.val().matches(/[a-za-z]$/i) &&              root.child('roles').child('$rol_id').child('description').val() !=              root.child('roles').child('$rol_id').child('description').exists()"            },           "state": {             ".validate":"newdata.isboolean()"           }         }     }, 

the problem can't enter in $rol_id unless give constant value need evaluate in each object.

this structure roles in firebase:

"roles" : {     "-kmohjag6djjebiq3oiv" : {       "creationdate" : 1468689365795,       "description" : "administrador",       "id" : "-kmohjag6djjebiq3oiv",       "permissions" : {         "inputs" : true,         "kardex" : true,         "outputs" : true,         "persons" : true,         "product" : false,         "rol" : true,         "sales" : true,         "supplier" : true,         "user" : true       },       "state" : true     }, } 


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -