OGeek|极客世界-中国程序员成长平台

标题: ios - Firebase 加入多个节点对象 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:51
标题: ios - Firebase 加入多个节点对象

我在尝试在 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...
     }
}

话虽如此,我的应用程序有一个仪表板 View ,它在 UICollectionView 中显示所有组/属性信息。它应该显示如下信息:

我将如何“加入节点”以便能够检索组信息以及属性信息;

基于登录到应用程序的用户是否属于组(因此在 UsersInGroups 节点中有一个条目)?!

UPDATE

关于数据结构的后续问题...

是否可以进行三 (3) 次连接以获取我希望在 UIColloection View 中显示的所有信息。

类似这样的:

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("roperties")
        ref.child(snap.key).queryEqual(toValue: true).observe(.value, with: { gamesnapshot in

              //Get all the info from firebase

        })
    })
 })



Best Answer-推荐答案


在您下载“群组”节点的所有地方,您是否需要特定群组的属性?如果这样做,您可以在“组”中创建一个新节点,将其命名为属性,并在其中列出所有属性。

关于ios - Firebase 加入多个节点对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44533078/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4