gpt4 book ai didi

javascript - 如何在 Parse 中获取对象和该对象的特定关系?

转载 作者:行者123 更新时间:2023-11-29 15:35:21 25 4
gpt4 key购买 nike

表格

_User
Default user class by Parse.com

tweet
objectId<string>
tweet<string>
tweetBy<string><Pointer _User>
createdAt<Date>
updatedAt<Date>

follow
objectId<string>
following<string><Pointer _User>
followedBy<string>
createdAt<Date>
updatedAt<Date>

Table data
------------------------------------------------------------------------
- _User -
------------------------------------------------------------------------
| objectId | username | password | email | createdAt | updatedAt |
------------------------------------------------------------------------
| z12ttttt | Matt | hidden | taz@taz.com |random time|random time|
| z12zzzzz | Jobs | hidden | anu@taz.com |random time|random time|
| z12bbbbb | Ballu | hidden | lon@taz.com |random time|random time|
| z12aaaaa | Stephin | hidden | zon@taz.com |random time|random time|
------------------------------------------------------------------------

-----------------------------------------------------------
- tweet -
-----------------------------------------------------------
| objectId | tweet | tweetBy | createdAt | updatedAt |
-----------------------------------------------------------
| blabla | Head Pain | z12ttttt |random time|random time|
| blab12 | Back Pain | z12ttttt |random time|random time|
| blab23 | Sleepy | z12ttttt |random time|random time|
| blab90 | Head Pain | z12zzzzz |random time|random time|
| blab90 | lets Dance| z12bbbbb |random time|random time|
| blab90 | lets jump | z12aaaaa |random time|random time|
-----------------------------------------------------------

-------------------------------------------------------------
- follow -
-------------------------------------------------------------
| objectId | following | followedBy | createdAt | updatedAt |
-------------------------------------------------------------
| blabla | z12ttttt | z12zzzzz |random time|random time|
| blabla | z12bbbbb | z12zzzzz |random time|random time|
-------------------------------------------------------------

期望的输出:

当前用户是 z12zzzzz ie Jobs

由于乔布斯正在关注马特和巴鲁,因此只会显示他们的推文

--------------------------------------------
Matt (3min ago)
Head Pain
--------------------------------------------
Matt (4min ago)
Back Pain
--------------------------------------------
Matt (5min ago)
Sleepy
--------------------------------------------
Ballu (5min ago)
lets Dance
--------------------------------------------

我的问题是让用户被关注,但没有关注他们的推文

        var username = window.localStorage.getItem('ls_username');
var Follow = Parse.Object.extend("follow");
var follow = new Parse.Query(Follow);
follow.equalTo('followedBy', username);
follow.include("following");
follow.include("tweet");
follow.include('tweet.tweetBy');
follow.find().then(function(results){
console.log(results);
var contentHtml = '';
for(i in results){
var object = results[i];
// Display individual tweets with their respected usernames
// Display only tweets of people being followed by currentuser
}
$('#globalTweets').html(contentHtml);
});

最佳答案

我认为问题是,给定一个用户,我们如何获得该用户正在关注的用户发布的推文?

var _ = require('underscore');
// need a user object, not a username, if the relational fields are pointers
var currentUser = Parse.User.current();

// find follows where the user is the follower
var followQuery = new Parse.query("follow"); // conventional class name would begin with caps
followQuery.equalTo("followedBy", currentUser);
followQuery.find().then(function(follows) {
// assume underscorejs
var followedUsers = _.map(follows, function(f) {
return f.get("following");
});
var tweetQuery = new Parse.Query("tweet");
tweetQuery.containedIn("tweetBy", followedUsers);
// aggressively fetch the authoring user info
tweetQuery.include("tweetBy");
return tweetQuery.find();
}).then(function(tweets) {
// tweets are tweets by users followed by the given user
});

关于javascript - 如何在 Parse 中获取对象和该对象的特定关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29903165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com