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

Configuring the JSON root for DjangoRESTAdapter #104

Closed
nikolas opened this issue Oct 1, 2014 · 8 comments
Closed

Configuring the JSON root for DjangoRESTAdapter #104

nikolas opened this issue Oct 1, 2014 · 8 comments

Comments

@nikolas
Copy link

nikolas commented Oct 1, 2014

Hi, I have an API response from Django REST Framework v2.4.3 that looks like this, for /api/puzzles/

{
    "count": 1, 
    "next": null, 
    "previous": null, 
    "results": [
        {
            "display_name": "test puzzle", 
            "description": "test puzzle description", 
            "created_at": "2014-10-01T17:57:25.223Z", 
            "updated_at": "2014-10-01T17:57:25.223Z"
        }
    ]
}

I've connected this to my Ember application with DS.DjangoRESTAdapter. When I run WeatherRoulette.__container__.lookup('store:main').find('puzzle'), ember-data says it's expecting a different format:

Error: Assertion Failed: The response from a findAll must be an Array, not {count: 1, next: null, previous: null, results: [object Object]}
    at new Error (native)
    at Error.EmberError (http://localhost:8000/site_media/WeatherRoulette/dist/assets/vendor.js:26705:23)
    at Object.Ember.assert (http://localhost:8000/site_media/WeatherRoulette/dist/assets/vendor.js:16889:15)
    at http://localhost:8000/site_media/WeatherRoulette/dist/assets/vendor.js:73434:15
...

I've forgotten how to customize the JSON root for ember-data. I just want to point it to results. Is there a simple config change for this? I'm using Ember 1.7.0, ember-data 1.0.0-beta.10.

Thanks.

@holandes22
Copy link

See #80, this adapter does not support pagination yet. To make it work you either need to modify the adapter (meaning, fix #80) or disable pagination on DRF

@benkonrath
Copy link

I'm working on updating the adapter to properly support ember-data beta.10 (#101). I think I should be able to get pagination working but I'm not sure if I'll hit some problems yet. I'm a bit busy with other work now but I'm hoping to get back to this shortly.

@nikolas
Copy link
Author

nikolas commented Oct 2, 2014

I'm looking at #101 and trying to fix those test failures. It looks like there's a lot of methods from DS.RESTAdapter to re-implement.

Maybe it would be better to configure django-rest-framework to return the JSON format that DS.RESTAdapter / DS.ActiveModelAdapter expects. I'm looking into that now.

@benkonrath
Copy link

Yeah, there's a some code for this by @Goldcap pointed to in #80

https://github.com/Goldcap/operis

I think the adapter needs a full rework. I guess it's just easy to deal with this server side like you suggest but there's still a benefit to having an adapter work with the default django-rest json when you can't change the server bits.

The code I have right now is processing the json into the right format on the JavaScript side instead of the server side.

If you just want to get something going, you can always use the adapter with ember-data beta.8 with ember 1.7.0. I'm using it in a project and it seems to be working ok.

@Goldcap
Copy link

Goldcap commented Oct 2, 2014

Hey, thanks for the shoutout, and yes, I eventually decided to implement most of the changes in Django. Also, note, my paginator only works for parent records, I had to implement a separate solution for pagination of many-to-many or one-to-many records.

Ping me back if anyone wants to see it, this WIP is fairly old already :)

@benkonrath
Copy link

@Goldcap If you're interested / have time it would be cool to see that work extracted to make it easier to find. I don't mean to add more work to your plate though. :)

@Goldcap
Copy link

Goldcap commented Oct 23, 2014

Hi Ben;

Absolutely, will upload probably this weekend. Sorry for the very late
reply! Everyone loves pagination.

On Fri, Oct 3, 2014 at 9:48 AM, Ben Konrath notifications@github.com
wrote:

@Goldcap https://github.com/Goldcap If you're interested / have time it
would be cool to see that work extracted to make it easier to find. I don't
mean to add more work to your plate though. :)


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

"If there is Evolution, why are there monkeys?" - Larry King

@dustinfarris
Copy link
Collaborator

Will be addressed in dustinfarris/ember-django-adapter#22

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

5 participants