Parse-server: Parse Relations not working after migration

Created on 25 Feb 2016  路  14Comments  路  Source: parse-community/parse-server

I migrated my data from parse to AWS EC2 and mongoDB (cancelled the migration as I just wanted the data for testing not to start using the new DB in production). My current code getting related objects using parse.com that is working fine is

$relation = $thisUnit->getRelation('unitImages'); $query = $relation->getQuery(); $unitImages = $query->find();

$thisUnit being a Unit object and 'unitImages' being of type Relation property (column) of that object.

There is more to this function, but I don't THINK its relative to the issue. The message I am getting from this function is:

Fatal error: Uncaught exception 'Parse\ParseException' with message 'Bad Request' in /var/www/html/vendor/parse/php-sdk/src/Parse/ParseClient.php:352 Stack trace: #0 /var/www/html/vendor/parse/php-sdk/src/Parse/ParseQuery.php(362): Parse\ParseClient::_request('GET', 'classes/?where=...', NULL, NULL, false) #1 /var/www/html/checkAvailabilityFunctions.php(153): Parse\ParseQuery->find() #2 /var/www/html/lodging.php(385): createUnitList(Array) #3 {main} thrown in /var/www/html/vendor/parse/php-sdk/src/Parse/ParseClient.php on line 352

This issue could be entirely predicated on me not having a firm understanding of how this data is supposed to be structured. When I do a find() on the mongo shell of all the Unit objects the Relation Field of unitImages in not there at all. I expected to see the field with some form of pointer to the Unit Images Class.

Am I just doing something wrong or is there supposed to be a field in the Units Class?

Thanks for the help.

bug

All 14 comments

Looking through the my mongoDB on AWS closer I do see that the _SCHEMA and _Join:unitImages:Units collections do connect everything nicely. So I am really confused.

Can you provide the initialization code for ParseClient, are you setting the server URL correctly, are other requests working? You can set the environment variable VERBOSE=1 on your parse-server machine and check the logs to see if the request is even hitting the right place.

app.js

var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app',
  cloud: '/var/www/html/js/cloud/main.js',
  appId: 'XXX',
  masterKey: 'XXX',
  serverURL: 'http://IP.compute-1.amazonaws.com:1377/parse'
});

checkFunctions.php (file function being called in)

require 'vendor/autoload.php';
  use Parse\ParseClient;
  use Parse\ParseCloud;
  use Parse\ParseObject;
  use Parse\ParseQuery;
  use Parse\ParseFile;

  ParseClient::initialize('XXX', 'notUsed', 'XXX');
  ParseClient::setServerURL('http://IP.compute-1.amazonaws.com:1377/parse');

Applicable query code in checkFunctions.php

$relation = $thisUnit->getRelation('unitImages');
$query = $relation->getQuery();
$unitImages = $query->find();

Ive tried a number of different standard queries in checkFunctions.php and they seem to be working fine.

Im very new to node so forgive me, but I'm not sure how to set VERBOSE=1. I assume its in the CL while in my /parse directory but am not sure on the command itself.

Im working on following the code to understand better how the SDK gathers relational information from my mongo instance. Im still not sure how $relation = $thisUnit->getRelation('unitImages'); gets anything considering if I do a find() in mongoDB shell of the "Unit Object" ($thisUnit) there is no property of 'unitImages'. Here is an example of what mongo find() gets me:

{
    "_id" : "uFIzHsrqTE",
    "unitMin" : NumberLong(2),
    "unitName" : "Brown Building",
    "unitNumber" : NumberLong(8),
    "unitDescription" : "Unit 8 Description",
    "unitMax" : NumberLong(8),
    "_updated_at" : ISODate("2015-11-14T16:10:08.895Z"),
    "unitRateType" : "small",
    "_created_at" : ISODate("2014-12-28T00:59:02.080Z"),
    "unitWebPageURL" : "http://ip/index.php/units-6-19",
    "unitAmenities" : [
        "Sleeps: Min 2 and Max 8",
        "Bedroom 1: 2 - Queen beds",
        "Bedroom 2: 1 - Queen bed",
        "Pull out sleeper",
        "Bathroom 1: Complete",
        "Bathroom 2: 4 person jacuzzi",
        "Complete kitchen",
        "Living room with Sat. TV, DVD ",
        "Wood buring fireplace",
        "Dog Friendly* (See Policies)",
        "*Images are generic of our 2 bedroom units"
    ],
    "mainImage" : "...-IMG_2286small.jpg"
}

I appreciate the fantastic support of this open source community.
If you need any other info just ask.

I was able to use a different query to get my expected results.

$query = new ParseQuery("UnitImages");
$query->equalTo('parentUnit', $thisUnit);
$unitImages = $query->find();

However it would still seem to me that the fact that my initial query works in hosted parse and not parse-server is still something of interest. I truly believe that the problem is in the migrated database specifically the collection "Units" not having the type Relation column "unitImages". Best I can tell following the code, using my initial query, it looks for that field in that collection and its just not there.

Getting this error when trying to save relations to a user after updating my app from 1.6.2 -> 1.12.0 in anticipation of migration. However after updating my iOS app "Tipped" which uses PFRelation a lot..... is super buggy, and weirdly the scroll performance on my collection views have dropped.

Here is the error response when trying to save a relation:

error response:
2016-03-01 15:24:29.415 Fashun[3408:883978] [Error]: PFKeychainStore failed to get object for key 'currentUser', with error: -34018
2016-03-01 15:24:29.421 Fashun[3408:883978] [Error]: PFKeychainStore failed to set object for key 'currentUser', with error: -34018
like obejct saved for Optional("bubbles")

Code:
let like = Like(photo: photo, user: user)

like.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
    if error == nil {
        let likeCreatedAtRelation = user.relationForKey("like_createdat")
        likeCreatedAtRelation.addObject(like)
        user.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
            self.photo.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
                self.transitionInProgress = false
                print("like obejct saved for \(user.firstName)")
            })
        })
    } else {
        print("error.userInfo: \(error!.userInfo)")
    }
}) 

@petek157 do you still face the issue or is that resolved for you?

My work around is working. But the "documented" way of querying a relation didn't seem to work. I haven't tried it again recently. I guess as far as my issue is concerned it is resolved. But Id say that there may still be a bug in the the server/database/migration regarding relation queries.

Yes, its still not working. I refactored our project to use pointer relationships instead of PFRelation.

Once i migrated the relations are gone. So my existing sub queries are not working any more. please fix this.

@lacker @shamain my app relies heavily on PFRelation. It's there any chance of this getting fixed? Its the only thing thats holding me back from migrating my app!

Hello Guys,

I am also not able to see the relation column on mongodb after migration can you please tell me that how would that show???

I had the same problem. After the parse migration, the response from the server doesn't include the relation. However, I just found out that even if it doesn't, response.relationForKey("relation_key") (in Swift) would retrieve the relation.

@ernestofndz, Can you pls let me know steps to get the relations ?

@shrimant-nikate-mobisoft sure. For example, your object Classroom has a relation called students, in this case each student is a PFUser.

  • First you would query the classrooms asynchronously PFQuery(className:"Classroom")
  • After getting the result of the query (array of [PFObject]), you would get the relation of each classroom let relation = classroom.relationForKey("students")
  • Having the relation, you can get the students with let objects = try relation.query().findObjects()
  • Iterate over the students if let student = objects[i] as? PFUser

Basically these are the steps, language is Swift but sure each SDK have similar methods.

Edit

Just noticed that while preparing the query, you should also include the key of the relation(s), e.g query.includeKey("students")

Was this page helpful?
0 / 5 - 0 ratings