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

support nested relations? #9

Open
tkellen opened this issue Feb 3, 2015 · 11 comments
Open

support nested relations? #9

tkellen opened this issue Feb 3, 2015 · 11 comments

Comments

@tkellen
Copy link

tkellen commented Feb 3, 2015

Some context:
In this example, an organization has projects and a project has phases. Sometimes, a user may wish to see the organization related to the phase, but not want the intermediate project record in the response.
This can be accomplished using endpoints with the following:

GET /project-phases/12?include=project.organizations

{
  "linked": {
    "organizations": [
      {
        "id": 12,
        "name": ".....",
      }
    ]
  },
  "project-phases": {
    "id": 1,
    "name": "Phase One",
    "project_id": 25,
    "first_day": "2014-04-21T04:00:00.000Z",
    "last_day": "2014-12-22T05:00:00.000Z",
    "links": {
      "project.organization": {
        "type": "organizations",
        "id": 12
      }
    }
  }
}

Is supporting this even possible with ember-data @bmac?

@leobalter
Copy link
Contributor

It looks it is possible and that's exactly the point where I am trying to solve on my project. The include parameter already works but when I use the async parameter in the model entries, it's not looking at the host and namespace.

@leobalter
Copy link
Contributor

link.related is a relative url and it's necessary to apply the host and namespace.

This can be seen at:

https://github.com/endpoints/ember-data-endpoints/blob/master/addon/json-api-adapter.js#L66

Where I changed both findBelongsTo and findHasMany to:

url = `${Ember.get(this,'host')}/${Ember.get(this,'namespace')}${link.related}`;

@bmac
Copy link
Member

bmac commented Apr 30, 2015

Interesting. I feel like endpoints should be returning the full url here. @tkellen thoughts?

@tkellen
Copy link
Author

tkellen commented Apr 30, 2015

No prob, I can update this (will do first thing tomorrow) It seems like
relative URLs should work tho?

On Apr 30, 2015, at 6:04 PM, Brendan McLoughlin notifications@github.com
wrote:

Interesting. I feel like endpoints should be returning the full url here.
@tkellen https://github.com/tkellen thoughts?


Reply to this email directly or view it on GitHub
#9 (comment)
.

@bmac
Copy link
Member

bmac commented Apr 30, 2015

@leobalter what does the JSON response from the endpoint look like? For some reason I can't get the v2 version of my api to work.

@leobalter
Copy link
Contributor

@bmac
Copy link
Member

bmac commented Apr 30, 2015

Thanks @leobalter.

@tkellen, I'd prefer not to add the complexity to the adapter to make it try and decide if it needs to add the namespace to a links url. However, if we and/or Ember Data did go down that route then I think these urls should not begin with a / as it makes them look like absolute urls instead of relative urls.

@tkellen
Copy link
Author

tkellen commented Apr 30, 2015

@bmac Try re-running get-secrets and provisioning? Working on the URLs thing now.

@tkellen
Copy link
Author

tkellen commented Apr 30, 2015

PS: I need to update the API to only run one version--the one you have checked out on your local machine.

The current deployment setup for the API clones and checks out each version--if you set currentVersion in group_vars/all.yml to v2, it will use the code you have checked out locally. Otherwise it's just a folder on the VM that you don't have access to from your local machine. Whoops.

/cc @bobholt if you have any more trouble.

@leobalter
Copy link
Contributor

IMHO, this looks very like an adapter responsibility. As the host and namespace is part of the adapter settings, relative links should also be resolved by the adapter.

My implementation on #18 is only a workaround and it needs to be improved (needs to check the existence of values, etc) but it seems weird to get the resolved url on the other cases.

@bmac
Copy link
Member

bmac commented May 1, 2015

@leobalter I disagree. The logic for building the urls should live in the server. It makes it easier to change that logic or update the url in the future without also requiring a change in the client.

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

Successfully merging a pull request may close this issue.

3 participants