【发布时间】:2017-06-13 23:24:17
【问题描述】:
我在尝试在 Firebase 中构造我的数据然后检索它时遇到问题,以满足此用例:
我有“用户”和“组”
{
Users:
LpWgezRkC6EWS0sjXEWxhFl2: {
userName: 'John Doe'
etc...
}
},
Groups:
12345: {
PropertiesID: 78765,
GroupName: 'MyPool',
GroupOwner: 'LpWgezRkC6EWS0sjXEWxhFl2'
GroupPassword: 'jkhdfjkhfdkjhdfkjhfsae4euhh4FDDC'
etc...
}
}
任何用户都可以加入任何组。
我将这种用户配对(关系)存储在“UserInGroups”节点中的组中。
{
UsersInGroups: {
DUmwewIfzAbfWZN4NjS8mhX82: { <- UserId
12345: true <- GroupId
},
LpWgezRkC6EWS0sjXEWxhFl2: {
12345: true
}
}
}
最后,每个组都有一个“属性”节点,用于控制组的细节/行为。
{
Properties:
78765: {
PropertyName: 'Custom',
dateCreated: '20170601',
etc...
},
76421: {
PropertyName: 'Admin',
dateCreated: '20170602',
etc...
}
}
话虽如此,我的应用程序有一个仪表板视图,它在 UICollectionView 中显示所有组/属性信息。它应该显示如下信息:
- 组名
- GroupOwner
-
基于“组”节点中的 PropertiesID
属性名称
属性创建日期
我将如何“加入节点”以便能够检索组信息以及属性信息;
基于登录到应用程序的用户是否属于组(因此在 UsersInGroups 节点中有一个条目)?!
更新
关于数据结构的后续问题...
是否可以进行三 (3) 次连接以获取我希望在 UIColloection 视图中显示的所有信息。
类似这样的:
let ref = firebase.database().ref("UsersInGroups")
ref.child((Auth.auth().currentUser?.uid)!).queryEqual(toValue: true).observe(.value, with: { snapshot in
let groupsRef = firebase.database().ref("Groups")
groupsRef.child(snapshot.key).observe(.value, with: { snap in
let propertiesRef = firebase.database().ref("Properties")
ref.child(snap.key).queryEqual(toValue: true).observe(.value, with: { gamesnapshot in
//Get all the info from firebase
})
})
})
【问题讨论】:
标签: ios swift firebase firebase-realtime-database