How do I get an object and specific relations of that object in Parse?

Tabby

Tables

_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   | [email protected] |random time|random time|
| z12zzzzz | Jobs     | hidden   | [email protected] |random time|random time|
| z12bbbbb | Ballu    | hidden   | [email protected] |random time|random time|
| z12aaaaa | Stephin  | hidden   | [email protected] |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|
-------------------------------------------------------------

Desired Output:

Curent user is z12zzzzz ie Jobs

Since Jobs is following Matt and Ballu only their tweet will be shown

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

my problem here is that am getting the users being followed but not their respected tweets

        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);
        });
danh

I think the question is, given a user, how do we get tweets made by users that the given user is following?

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
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PhalconPHP - get specific object with multiple relations

From Dev

How do I set a timer for a Parse object?

From Dev

How do I parse this JSON Result as an object?

From Dev

How do I parse a JSON object in JavaScript

From Dev

How do I delete a specific Parse Object's row within IBACTION?

From Dev

Parse.com PHP SDK Get User Relations for Object

From Dev

How can I delete a specific object from Parse query results?

From Dev

How do I get the value of a @ object attribute?

From Dev

how do i get this object to setText in GUI

From Dev

How do i refer to a get function as an object

From Dev

How do i get a graphics object in Java?

From Dev

How do i get Object index in an array

From Dev

How do i refer to a get function as an object

From Dev

How do I get the extended object in php?

From Dev

How do I get the index of an object in this array?

From Dev

How do I get the address of an object with an interface?

From Dev

How do I get the json nested object?

From Dev

How do I get a specific object from an immutable js map by value?

From Dev

How do I get specific object's attributes after a related event?

From Dev

How do I get a key value of each object in a javascript object?

From Dev

How do I check if an object on Parse is nil, in Swift?

From Dev

In iOS, how do I parse a JSON string into an object

From Dev

How do I check if the value is defined for a key of an object in Parse Android?

From Dev

How do I parse "/Date(1459934700000)/" into a JavaScript Date object?

From Dev

How do I parse the following object array to the following format for displaying

From Dev

How to parse? json object values into specific inputs

From Dev

How to delete specific object from Parse?

From Java

How do I check if an object has a specific property in JavaScript?

From Dev

Meteor: how do I return data from fields in a specific object?

Related Related

  1. 1

    PhalconPHP - get specific object with multiple relations

  2. 2

    How do I set a timer for a Parse object?

  3. 3

    How do I parse this JSON Result as an object?

  4. 4

    How do I parse a JSON object in JavaScript

  5. 5

    How do I delete a specific Parse Object's row within IBACTION?

  6. 6

    Parse.com PHP SDK Get User Relations for Object

  7. 7

    How can I delete a specific object from Parse query results?

  8. 8

    How do I get the value of a @ object attribute?

  9. 9

    how do i get this object to setText in GUI

  10. 10

    How do i refer to a get function as an object

  11. 11

    How do i get a graphics object in Java?

  12. 12

    How do i get Object index in an array

  13. 13

    How do i refer to a get function as an object

  14. 14

    How do I get the extended object in php?

  15. 15

    How do I get the index of an object in this array?

  16. 16

    How do I get the address of an object with an interface?

  17. 17

    How do I get the json nested object?

  18. 18

    How do I get a specific object from an immutable js map by value?

  19. 19

    How do I get specific object's attributes after a related event?

  20. 20

    How do I get a key value of each object in a javascript object?

  21. 21

    How do I check if an object on Parse is nil, in Swift?

  22. 22

    In iOS, how do I parse a JSON string into an object

  23. 23

    How do I check if the value is defined for a key of an object in Parse Android?

  24. 24

    How do I parse "/Date(1459934700000)/" into a JavaScript Date object?

  25. 25

    How do I parse the following object array to the following format for displaying

  26. 26

    How to parse? json object values into specific inputs

  27. 27

    How to delete specific object from Parse?

  28. 28

    How do I check if an object has a specific property in JavaScript?

  29. 29

    Meteor: how do I return data from fields in a specific object?

HotTag

Archive