0

I have 2 spinners ,for services and employees.

in my app i want to let user choose list of services then i fill the employee spinner only for employee who available for that service

i have employee class and structure similar like this :

  "Employees" : {
        "eid1" : {
          "name" : "john",
          "services" : {
 //john has 3
            "sid1" : "true",
            "sid2" : "true",
            "sid3" : "true"        
          },
        "eid2" : {
          "name" : "david",
          "services" : {
 //david only has 1
            "sid2" : "true"                   
          }        
        }

my service structure is :

"Services" : {
        "sid1" : {
          "name" : "read"                    
          },
        "sid2" : {
          "name" : "write"                  
          },
        "sid2" : {
          "name" : "erase"                  
          }           
        }

example: if i choose service2, the query will find john and david. if i choose service1 then only john will be fetched and added to my spinner.

i confuse what the query i should use, i tested some, including this, but always skipped when i run it in debug mode:

       mDatabase.child("Employees").orderByChild("services").equalTo(serviceList.get(position).getName()).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot dsp : dataSnapshot.getChildren()) {

                //System.out.println(dsp.getKey());
            }

        }
Goofy_Phie
  • 671
  • 1
  • 8
  • 25
  • From a quick read I get the feeling your data model is not well suited for the query you're trying to write. See http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Apr 22 '17 at 15:03
  • thankyou, based on the link you provided, i need to change my structure. that might work, i'll try it later. but actually i made that structure after reading the firebase doc(structure data) , the sample did like that, user: {alovelace { name:alovelace, group:{ techpionner:true} , that just like my employee with services nested its key. , what i am missing here sir? – Goofy_Phie Apr 22 '17 at 15:32
  • That data model allows you to easily find the users in a specific group. It does not easily allow you to find the groups for a specific user, which is more what you're trying to do. In NoSQL you often model/augment the data for the use-cases of your app. Read [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/) and view [Firebase for SQL developers](https://www.youtube.com/playlist?list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s). – Frank van Puffelen Apr 22 '17 at 15:43
  • in contrary sir, i think what i want is to find users (employee) in a specific group (service). so if the service is Write, then i want to find all users who can write. i want to add all those users in my spinner – Goofy_Phie Apr 22 '17 at 15:54
  • That makes me even more confused. Why don't you simple store the value "read", "write" or "delete" straight under each employees services? That would simplify you data model and move it back to what I linked: you want a list of employees for a specific service? Model your data to have a list of employees for each service. – Frank van Puffelen Apr 22 '17 at 22:38
  • oh i see it now, thank you sir. – Goofy_Phie Apr 23 '17 at 04:02
  • btw, how to end/close this question? admin, what should i do? – Goofy_Phie Apr 23 '17 at 04:03

0 Answers0