Search code examples
javascriptparsingparse-platformparse-server

Javascript with Parse: Error 111 expected Pointer but got [object Object]


So i got some Problems with Pointer in Parse Server. I got a Table, that connect two other Tables with Pointers.

Example:

var table1id  //ID of the first table
var table2id  //ID of the second Table
var Example = Parse.Object.extend('example_table');

function add_newExample(table1id, table2id) {
    var example = new Example();
    example.set('table1_id', table1id);
    example.set('table2_id', table2id);
    example.save(null, {
        success: function () {
            console.log('New object created');
         },
        error: function (error) {
            console.log('Failed to create new object');
        }
    })
}

Error:

code: 111 error: "schema mismatch for example_table.table1id; expected Pointer but got [object Object]"


Solution

  • It's not clear from the code above what the fields for table1_id table2_id are supposed to be or what you have them set to.

    If you look at example_table in the dashboard, what type do the columns say they are?

    But I'll assume that they should be pointer to rows in other tables (based on the error you're getting), in which case, the below should work for you.

    const Example = Parse.Object.extend('example_table');
    
    const Table1 = Parse.Object.extend('table1');
    const table1Ptr = new Table1().set('objectId', '1');
    
    const Table2 = Parse.Object.extend('table2');
    const table2Ptr = new Table2().set('objectId', '6');
    
    const addNewExample = function addNewExample(table1Ptr, table2Ptr) {
      // return the promise that results from the save
      return new Example() // just chaining everything to be terse...
        .set('table1_id', table1Ptr)
        .set('table2_id', table2Ptr)
        .save(null, { useMasterKey: true }) // may not be necessary, depending
        //
        // don't use these old style handlers, use promise syntax
        // which I substitute for the following below.
        // success: function () {
        //    console.log('New object created');
        // },
        // error: function (error) {
        //    console.log('Failed to create new object');
        // }
        .then(
          // fancy fat arrow notation for functions like the cool kids...
          o => console.log('new object: ' + o.id + ' created'),  
          e => console.error('uh oh: ' + e.message)
        );
    };
    
    addNewExample(table1Ptr, table2Ptr);