Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating resource relationship linkages during a resource create #227

Open
devotox opened this issue Jun 8, 2017 · 6 comments
Open

Creating resource relationship linkages during a resource create #227

devotox opened this issue Jun 8, 2017 · 6 comments

Comments

@devotox
Copy link

devotox commented Jun 8, 2017

Creating a resource relationship questions

  • How should the data look like for the relationship. Just a regular POJO or a full JSON API spec set
    i.e. with { id: 123, attributes: { name: ... } }

  • The reason why the relationship is null is because Ember sends any relationship with no data as null and expects the backend to handle it

  • It seems the problem is that it is trying to set nothing where userid=$1

Versions

"loopback": "2.38.1",
"loopback-component-jsonapi": "2.2.1",
"loopback-connector-postgresql": "2.7.0",

Error

database_1         | STATEMENT:  UPDATE "public"."profile" SET  WHERE "userid"=$1
api_1              | 22:06:55 0|api      | { error: syntax error at or near "WHERE"
api_1              | 22:06:55 0|api      |     at Connection.parseE (/tmp/api/node_modules/pg/lib/connection.js:572:11)
api_1              | 22:06:55 0|api      |     at Connection.parseMessage (/tmp/api/node_modules/pg/lib/connection.js:396:17)

Data sent

{
    "data": {
        "attributes": {
            "email": "devo.tox.89@gmail.com0.3078582477029794",
            "realm": null,
            "status": null,
            "username": "devotox0.9883987623877892",
            "password": "dev",
            "challenges": null,
            "lastupdated": null,
            "emailverified": false,
            "created": "2017-06-08T21:52:35.513Z"
        },
        "relationships": {
            "profile": {
                "data": null
            }
        },
        "type": "users"
    }
}
@digitalsadhu
Copy link
Owner

Interesting. Yes it certainly looks like its because its trying to set nothing in that update statement.
Does this just happen for creates? I assume so. I'll put together a test case and see if I can replicate.

Thanks for reporting

@digitalsadhu
Copy link
Owner

Wrote a quick test. No failures when using the memory connector. Probably to be expected.
I'm a bit surprised I haven't run into this before. Does just simply defining a relationship to profile on user in ember mean than whenever you create a user it sets that null profile data?

@devotox
Copy link
Author

devotox commented Jun 18, 2017

@digitalsadhu Yes just having a belongsTo relationship without even actually populating it will always create a null value. Also if there is profileData it does not actually send the data just the id there so it would look something like this

Data sent

{
    "data": {
        "attributes": {
            "email": "devo.tox.89@gmail.com0.3078582477029794",
            "realm": null,
            "status": null,
            "username": "devotox0.9883987623877892",
            "password": "dev",
            "challenges": null,
            "lastupdated": null,
            "emailverified": false,
            "created": "2017-06-08T21:52:35.513Z"
        },
        "relationships": {
            "profile": {
                "data": 1
            }
        },
        "type": "users"
    }
}

@digitalsadhu
Copy link
Owner

Hmm,
Something fishy going on there. Do you mean ember is sending that id?

"relationships": {
   "profile": {
     "data": 1
   }
},

If thats the case as I'm sure you know that is invalid.

It should send either:

"relationships": {
   "profile": {
     "data": null
   }
},

or

"relationships": {
   "profile": {
     "data": {
        "id": 1,
        "type": "profiles"
      }
   }
},

Or did you mean that the server is responding with that invalid data?

Are you able to paste model definitions, server response and client payloads?

@devotox
Copy link
Author

devotox commented Jul 8, 2017

I will try and get you this by tomorrow or monday just saw your reply now. But even before the problem with how it is sending back the relationships when there is data we should handle what happens when there the data is null by loopback

@digitalsadhu
Copy link
Owner

Cool thanks! I'm on holiday for the next 2 weeks. Probably wont be at my computer a whole lot so no rush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants