ember-parse-adapter icon indicating copy to clipboard operation
ember-parse-adapter copied to clipboard

Relationships are not persisted correctly

Open igorsantos07 opened this issue 11 years ago • 6 comments

When trying to store a relationship in Parse I get the following 111 error in the HTTP response: invalid type for key customer, expected relation<Item>, but got "Item"

The payload sent includes a customer key with this object: { __type: "Pointer", className: "Item", "objectId": "D2zBq..." }

That was made through the console, with the following code just for the purpose of testing how things work:

models = controller.model;
models.hypotheses.objectAt(0).set('customer', models.customers.objectAt(0));
models.hypotheses.objectAt(0).save();

I guess the adapter is not correctly naming relationship objects before sending?

igorsantos07 avatar Apr 14 '15 05:04 igorsantos07

@igorsantos07 Any updates on this?

philipheinser avatar Apr 16 '15 11:04 philipheinser

None. I'm focusing on other parts of my project for awhile, hoping the maintainer will take a look at this weird bug.

igorsantos07 avatar Apr 17 '15 02:04 igorsantos07

It would be great if you could share the code for describing your models. Then it would be possible to trace why your column is set to relation<Item> as oppose to pointer<Item>

denzo avatar Apr 25 '15 04:04 denzo

Hypothesis = DS.Model.extend
  customer:          DS.belongsTo 'item', async: true
  problem:           DS.belongsTo 'item', async: true
  solution:          DS.belongsTo 'item', async: true
  risk:              DS.belongsTo 'item', async: true
  method:            DS.attr 'string'
  criterion_total:   DS.attr 'number'
  criterion_valid:   DS.attr 'number'
  criterion_invalid: DS.attr 'number'
  status:            DS.attr 'boolean', defaultValue: null
  text:              DS.attr 'string'

igorsantos07 avatar Apr 25 '15 05:04 igorsantos07

Hey, I think I accidentally found the issue! The problem lies in the type of relations I'm creating at Parse. I've created the tables before persisting them, instead of using a master key. I've stumbled across the Relations doc, and noticed there are actually four ways to build those. I'll take a look at how that behave with the adapter code and report soon :)

igorsantos07 avatar Apr 25 '15 15:04 igorsantos07

I'm fixing my relations in my models and Parse tables. It seems it was a conflict of types.

However, this surfaces an important stuff: we need clear documentation on what Ember relations are what Parse relation types. Also, would be cool to see a clearer error message (example: in case someone uses one-to-many in Ember and Relation [suited for many-to-many] in Parse).

igorsantos07 avatar Apr 25 '15 17:04 igorsantos07