0

I'm trying to understand how relation works and i did wrote this simple script:

var Parse = require('parse/node');

Parse.initialize('myAppId');
Parse.serverURL = 'http://localhost:1337/parse';

var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo('username', 'the_username');

userQuery.find()
    .then(user => {
        return user;
    })
    .then(user => {
        var Systems = Parse.Object.extend("systems");
        var systemQuery = new Parse.Query(Systems);
        systemQuery.equalTo('customer', 'myCustomer');

        systemQuery.find()
            .then(system => {
                var relation = user.relation('systems_ref'); // HERE I GET RELATION IS NOT A FUNC
                relation.add(system);
                console.log('Adding relation');

                user.save()
                    .then(response => console.log('user saved'))
                    .catch(error => console.log('Error saving', error));
            }).catch(error => console.log('Error find system', error));
    });

But in the line where i try to get user.relation i have the error "Relation is not a function".

I have look others example on how to create a relation, but i dont see difference in my code...

I have the user (that is a sublcass of ParseObject), and on it i'm trying to access relation method...

1 Answer 1

1

You may use it as follows: To add the Post to User with the JavaScript SDK:
var user = Parse.User.current();
var relation = user.relation("posts");
relation.add(post);
user.save();

Sign up to request clarification or add additional context in comments.

2 Comments

maybe you are not getting user obecjt where you are calling relation for this. you can console and find if it is ok or not.
I've placed console.log everywhere and all works... i get the User back and is an instance of ParseUser... Maybe with User.current() will works, but i will need to do this in the "Administration" page i'm building, so i cand use the current user, because i have to add relation to others user. I will user array of Pointer if this do not works :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.