下面是数据库结构.我有一些链接到评论后的帖子.我试图获取特定用户添加评论的所有帖子:
{ "posts" : { "-KIycKhZU55dmKnHbbxv" : { "author" : "John Doe","body" : "This is a post test","Title" : "test","uID" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" },"-KIyg_ks1O5QL4_4dfq_" : { "author" : "Jane Doe","Title" : "test2","uID" : "x5leSBGArnd10JilD9YDyNBNfZ03" },... } "post-comments" : { "-KIycKhZU55dmKnHbbxv" : { "-KIycMyL0Vy1BHVdI4zc" : { "author" : "toto","text" : "test","uID" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" },"-KIyg_ks1O5QL4_4dfq_" : { "author" : "toto","uID" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" } },... }
在sql中,这将被翻译成类似于的内部联接查询:
选择*来自post post的内部联接后评论post-comments.uID =“user ID”
有人知道如何在firebase中获得类似于内连接的东西吗?
非常感谢,
亚辛
ref.child("posts").observeEventType(.ChildAdded,withBlock: { (snapshot) in if let postID = snapshot.key as! String { let commentsRef = ref.child("post-comments") commentsRef.child(postID).queryOrderedByChild("uID").queryEqualTovalue(userID).observeSingleEventOfType(.Value,withBlock: { (snapshot) in for child in snapshot.children.allObjects as [FDataSnapshot] { print(child.value) } }) { (error) in print(error.localizedDescription) } }})总结
以上是内存溢出为你收集整理的ios – FIRDatabaseQuery:如何进行内连接全部内容,希望文章能够帮你解决ios – FIRDatabaseQuery:如何进行内连接所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)