@@ -61,7 +61,7 @@ var schema = FirebaseSchema.create(Firebase, HOST, (child) => {
61
61
- Now its easy to see what kind of data you save and where. Since the
62
62
schema is defined as a nested route structure, we don't have to leave
63
63
the key: value paradigm of Firebase.
64
- - Relationships via ` index ` and ` key ` get looked up for you
64
+ - Relationships via ` index ` and ` key ` get looked up for you ( https://www.firebase.com/docs/web/guide/structuring-data.html )
65
65
- Data is validated when you try to ` set ` or ` push ` to a path.
66
66
- ` list ` s are automatically converted to an array when you retrieve the
67
67
value, with their keys assigned to ` _id ` .
@@ -74,7 +74,13 @@ var groupId;
74
74
75
75
usersRef .push ({name: ' Ryan' }, () => {
76
76
usersRef .getValue ((err , val ) => {
77
- console .log (val); // [{ name: 'Ryan', _id: 'flkajsdf' }]
77
+ deepEqual (val, [{
78
+ name: ' Ryan' ,
79
+ // woah what's this? since we did `child('users', list, ...)`
80
+ // we get the values back as an array with their firebase key
81
+ // set as the `_id`
82
+ _id: ' -Jev95piCGXV9jX4ellH'
83
+ }])
78
84
userId = val[0 ]._id ;
79
85
});
80
86
});
@@ -87,7 +93,7 @@ groupsRef.push({ name: 'cool kids table' }, () => {
87
93
groupsRef .getValue ((err , groups ) => {
88
94
groupId = groups[0 ]._id ;
89
95
// define a relationship between the group and the user using
90
- // a `key:true` index
96
+ // a `key:true` index (https://www.firebase.com/docs/web/guide/structuring-data.html)
91
97
groupsRef .child (` ${ groupId} /members/${ userId} ` ).set (true );
92
98
usersRef .child (` ${ userId} /groups/${ groupId} ` ).set (true );
93
99
});
@@ -96,11 +102,13 @@ groupsRef.push({ name: 'cool kids table' }, () => {
96
102
// later
97
103
98
104
groupsRef .getValue ((err , groups ) => {
99
- console .log (groups[0 ]);
100
105
deepEqual (groups[0 ], {
101
106
name: ' cool kids table' ,
102
107
_id: ' -Jev95pjLLtDmIxbGhcF' ,
108
+ // woah what's this?
103
109
_indexes: {
110
+ // because we defined `child('members', index(...))` we
111
+ // get an array of paths to the members of this group
104
112
members: [
105
113
' users/-Jev95piCGXV9jX4ellH'
106
114
]
0 commit comments