0

This is the structure of my data at firebase Realtime database

So there are members and all of them submits fee at monthly basis so I created separate reference for their fee records to make structure more flat.

under the "fee" the top level keys are the keys of member to which the records belong, so that i can query records for specific memebers and then inside it there are fee records which have their own key, so how do i query only the fee records.

because it want to pull the only fees data in a FirebaseRecyclerAdaper what i have done so far is.

 Query baseQuery = FireBaseHandler.getInstance(getActivity()).getFeeReference();
    FirebaseRecyclerOptions<FeeRecord> options = new FirebaseRecyclerOptions.Builder<FeeRecord>()
            .setLifecycleOwner(this)
            .setQuery(baseQuery,FeeRecord.class)
            .build();

    mAdapter = new FirebaseRecyclerAdapter<FeeRecord,Holder>(options) {

        @Override
        protected void onBindViewHolder(@NonNull final Holder holder, int i, @NonNull FeeRecord feeRecord) {

        }
        @NonNull
        @Override
        public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(getActivity());
            return new Holder(inflater,parent);
        }

But the baseQuery here only return everything under fee and send them to recycler adapter but it is returning only two children , which you can see why in the structure above . How do i get feeRecords inside these two children and lay them in the recycler view.

Or do you recommend changing the structure

Thanks in advanace

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Abhinav Chauhan
  • 985
  • 1
  • 4
  • 20
  • These keys connected to any user ? or any other relationship of this keys please provide – Ashish Mar 21 '20 at 12:04
  • as i mentioned the two top level keys are the keys of members two which the records under them belongs , but the keys for a those records are generated by push() method which i didn't mention – Abhinav Chauhan Mar 21 '20 at 12:10
  • if those keys are related to member. You used firebase auth ? – Ashish Mar 21 '20 at 12:18
  • no members don't use the app, i is the gym owner who use it, so the current owner is the gym owner – Abhinav Chauhan Mar 21 '20 at 12:31
  • the leftmost vertical line in the structure belongs to the current user, his key is not shown in this image – Abhinav Chauhan Mar 21 '20 at 12:37
  • What is the reason for using those two pushed ids? Please also respond with @AlexMamo – Alex Mamo Mar 21 '20 at 13:30
  • @AlexMamo if i don't ids for records then how do i put them under member specific id, the one at the top sX ,in the end is the id of a member similary one ending with RI also, so whenever i need the records for that member i will take the member id , and find his set of records using it, those records also also need to have id otherwise how do it save them, and record don't need to have an id inside it as a field, i shall remove that id field for it, just date, name ,amount is sufficient – Abhinav Chauhan Mar 21 '20 at 13:50
  • @Ashish read the comments – Abhinav Chauhan Mar 21 '20 at 13:51
  • I'm having a hard time understanding what you explain. Please tell me the reason why those pushed ids are present and what you intend to get. What is the expected result;t? – Alex Mamo Mar 21 '20 at 14:32
  • @AlexMamo so the date,name,amount represent a feerecord, i can pull these with memberid and convert them in fee records by calling databasereference.child(getCurrentUser().getUid()).child("fees").child(member.getMemberId) becasue member id is the same as top level id for all his records, then i can call getChildren() on the returned sanpshot and access all the records. – Abhinav Chauhan Mar 21 '20 at 15:01

1 Answers1

1

The adapter in FirebaseUI are made to display a single flat list of data from the Realtime Database. So in your data model, they can either display the list of users (the nodes directly under /fees), or the fees for one specific user (the nodes under one /fees/$pushid).

The FirebaseUI adapters cannot display all nodes in a tree, or at least not without significant modification on your part.

I recommend:

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
  • means i can't use firebaseRecycler adapter and need handle datachanges myself with the custom adapter – Abhinav Chauhan Mar 21 '20 at 14:56
  • 1
    I gave you two options. Whether you choose to pick one or the other is up to you, but I wouldn't immediately discard changing your data model. Changing/expanding your data model for a specific use-case is quite common when using NoSQL data models. If this is new to you, I recommend reading [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/)l, and watching [Firebase for SQL developers](https://www.youtube.com/playlist?list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s). – Frank van Puffelen Mar 21 '20 at 15:01
  • is there any documentation for FirebaseRecyclerAdapter , that github repo does not provide all details – Abhinav Chauhan Mar 21 '20 at 15:04
  • can you also suggest me how to flat these fee records ,i somehow need to identify a record then how do i do it without putting them under an id – Abhinav Chauhan Mar 21 '20 at 15:10
  • 1
    1) Given that FirebaseUI is an open-source library, the github repo provides all the details that exist. If you have a specific question, we can try to answer. 2) There are many ways to denormalize, and covering them is far beyond what can be done in a single answer, let alone in a comment. Two main options are to make your tree a flat list (either duplicating existing data, or replacing the existing structure). In either case, you'll need to include the information you need in each child node in the flat list, so possibly also include the member ID in each fee node there. – Frank van Puffelen Mar 21 '20 at 15:24
  • thankyou very much, i understand i can not be answered here ,but still you provided valuable information i was asking for documentation , because i didn't find what the methods like setIndexedQuery() does , which according to android studio i can call on new FIrebaseRecyclerOptions.Builder<>(),there are other methods too – Abhinav Chauhan Mar 21 '20 at 15:27
  • sir with your guidance i solved the above problem but now i need to query data in reverse , lets say i can sort by name and people with A as first letter in the name comes first but i want people with Z as first letter – Abhinav Chauhan Apr 01 '20 at 05:04
  • 1
    Firebase always returns the results in ascending order. Reversing database results (both with FirebaseUI and without it) has been covered regularly, so I recommend searching for it. – Frank van Puffelen Apr 01 '20 at 14:30