parse.com - Using Firebase (iOS-Swift) for user's Read/Write data storage -


i'd start using firebase main baas parse closing. @ moment, firebase's real-time capabilities interesting , see using them in future, i'd use firebase way store user , there associated data. parse, super easy, required uploading object associated user attached object. filter objects associated user.

however, in firebase event driven opposed on-demand , can't filter security rules. in general, approach, i'm having trouble applying need today. don't have of background in networking/databases, possible of stuff basic.

here i'm looking do:

my firebase data structure looks currently:

xnterval    users       100b920f-d2c5-4578-9f49-ecf38ef71302       32a8dbf2-009a-44c5-a188-ca2c280ba135       d53b0b37-d773-4cf5-af94-74635fc76f1f          name: "joe schmo"          provider: "password"          username: "jschmo"          workouts             -k9wz4_rt-xbdvzt93d4                 workout_id: "-k9wz4_rt-xbdvzt93d3"    workouts       -k9wz4_rt-xbdvzt93d3             interval_period: 180             intervals: 2             name: "workout"             owner: "d53b0b37-d773-4cf5-af94-74635fc76f1f"             rest_period: 150             work_period: 30 

enter image description here

inside user/"uid" have workouts list order childbyautoid , contains id of single workout.

what want able do, list of user's workouts , retrieve complete workout list workouts section.

i know path directly users workouts root/"uid"/workouts, how retrieve entire list , each "workout_id" , subsequently query list of workouts in /workouts section?

i've setup security rules such no other user can access users data, , user can read/write workout if owner of workout uid on authenticated user. have working correctly.

maybe i'm going wrong way, or there easier way structure data accomplish want. read few articles on de-normalizing data in order optimize amount of transfer required in query, , building future feel data structure ideal that. if have more experience, please let me know. thanks!

update

so i've create method retrieve user's workout id's , store them array userworkoutids:

private func observealluserworkouts() {     if userauthdata != nil {         workoutobserver = userref?.childbyappendingpath("workouts").observeeventtype(feventtype.value, withblock: { snapshot in             let enumerator = snapshot.children             while let child = enumerator.nextobject() as? fdatasnapshot {                 nslog("\(child.childsnapshotforpath("workout_id").value)")                 self.userworkoutids?.append(child.childsnapshotforpath("workout_id").value as! string)             }         })     } } 

now know paths of users workouts /workouts/"ids", how can poll of them @ once opposed setting single shot observers different paths? or option?

a super quick solution: add uid of user workout_id node.

then can query on workouts node uid equal user of workouts want retrieve.

workouts    workout_id_0      interval_period: 180      internvals: 2      uid: user_id    workout_id_1      interval_period: 180      internvals: 2      uid: user_id 

a second option:

if know path user workouts

/users/uid_id/workouts

you observe node value, read in of children in node snapshot. iterate on snapshot specific data. load each item in snapshot array of dictionaries or maybe workout object.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -