android


Firebase Android unable to query item based on object value - returns all values


I have been working on a Firebase backed Android app and this is what my datatbase looks like
{
"Category" : {
"-KhHnKaR2oS0JKNrAQWr" : {
"CategoryDescription" : "Ne est",
"CategoryName" : "New Test Category",
"CategoryThumbnail" : "/New Test Category/New Test Category-thumb.jpg",
"ThumbnailFileType" : "jpg"
}.......
},
"Images" : {
"-KhHBBI4QloAEBDxcUac" : {
"Category" : "-KhBGZnCQ5xhYVbP0dtd",
"-KhBGZnCQ5xhYVbP0dtd":true,
"CategoryName" : "please",
"FileType" : "jpg",
"FileURL" : "/please/NewAddTest.jpg",
"Name" : "NewAddTest"
},
"-KhI1wWJK8YUApa0Iv9q" : {
"Category" : "-KhHnKaR2oS0JKNrAQWr",
"-KhHnKaR2oS0JKNrAQWr":true,
"CategoryName" : "New Test Category",
"FileType" : "jpg",
"FileURL" : "/New Test Category/Test Mem.jpg",
"Name" : "Test Mem"
}.....
}
}
And I was able to get categories by referring the key 'Category' and initially I had Cateogry and Images embedded i.e,
"-Kh8YUXwK0sg3OyoTyAU" : {
"CategoryDescription" : "The legendary evergreen Vadivelu",
"CategoryName" : "Vadivelu",
"CategoryThumbnail" : "/Vadivelu/v2.png",
"Images":{"-KhH5nJjaji2OtOPVeQF" : {
"Category" : "-KhBGZnCQ5xhYVbP0dtd",
"-KhBGZnCQ5xhYVbP0dtd":true,
"FileType" : "jpg",
"FileURL" : "/please/New jpg",
"Name" : "New "
}}
}
It worked out well but in the Firebase docs I read that it is safer to keep data normalized and flattened so then I came up with the latest one at the top. When I try to query like below it returns all objects rather than the desired ones,
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference imageRef = database.getReference("Images");
imageRef.keepSynced(true);
try {
imageRef.child("Images").
orderByChild("Images/Category").equalTo(category.memeCategoryID);
imageRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Returns all objects.
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
Also I tried to do this,
imageRef.child(category.CategoryID).equalTo(true);
What I intend to do here is implement by multiple - single relationship and fetch all Images tagged to a category, any help is appreciated. I have seen so many threads and the official Firebase documentation is really confusing and does not help me a bit.
When you call orderBy..., equalTo or one of the other methods, Firebase returns a new Query object. So you'll need to capture that query in a new variable:
Query query = imageRef
.child("Images")
.orderByChild("Images/Category")
.equalTo(category.memeCategoryID);
query.addListenerForSingleValueEvent(new ValueEventListener() {

Related Links

Android create intent to start activity
Is it possible to install android market on android sdk
Log In to Website
PNG file won't display in ImageView if source is set programatically
Can I throw my own strict mode violation [on Android]?
Android 3 Spinners
“Refresh Property Sheet” has encountered
InflateException: Couldn't resolve menu item onClick handler
The visibility of the items change when scrolled ListView
Change Seek bar progress color?
Version Change issue in Android App
Is it possible to use private Samsung frameworks in my own app?
Image's consuming web service on android eclipse
making an activity touchScreen
admob to listactivity confusing me
Adobe Air Mobile (iOS, Android) and Incoming Phone Calls

Categories

HOME
cobalt
delphi-7
checkstyle
awk
github-for-windows
pda
interface
jsf-2.2
can
tivoli
character
qpython
p2p
syntaxnet
ycsb
cmdb
openbugs
nancy
pybossa
delphi-xe5
sar
roslyn
jquery-callback
direct3d11
onload
apktool
linked-data
android-things
sinch
r-grid
vue-chartjs
fiware-cygnus
swagger-php
verifiable-c
typesafe-config
xv6
postgresql-8.4
lpsolve
vaadin-charts
x++
textsum
geotiff
posixct
magic-draw
pair-programming
headless
janus
gpg-signature
jtree
renaming
simplepie
synonym
cifilter
shopping
spreadjs
thread-sleep
highland.js
inf
custom-errors
terracotta
vigenere
visual-sourcesafe-2005
mod-proxy
zscript
dronekit-android
viewer
spring-remoting
multiautocompletetextview
gd-graph
beaker-testing
jquery-1.9
actiondispatch
intersect
dopostback
redis-py
mkv
fusefabric
fitbounds
updatesourcetrigger
aspmenu
lxr

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App