How to hit endpoints without REST with Ember Data 1.0 beta

My API basically calmed down, except that some resources have an endpoint /search. I use DS.ActiveModelAdapterboth DS.ActiveModelSerializerand everything is fine.

My current search implementation looks something like this:

makeAPICall: ->
  @set('loading', true)

  states = @get('selectedStates')
  statesString = states.join(',')
  query = @get('searchParam')
  url = "/api/v1/organizations/search?#{statesString}&query=#{query}"

  $.get(url).then (data) =>
    @get('store').pushPayload(data)
    # TODO this needs to go through the adapter.
    orgs = data.organizations.map (org) =>
      @store.find('organization', org.id)
    @set('organizations', orgs)
    @set('loading', false)

The problem is that I don’t know how to do all the normalization / camelization that happens in the adapter in this case. Because the template relies on @get('organizations'), in this case some underlined attributes are not displayed.

What is the correct way to implement this?

0
source share
1 answer

PushPayload /, , , ... v1.0.0-beta.3

var pushData = {
  posts: [
   {id: 1, post_title: "Great post", comment_ids: [2]}
  ],
  comments: [
    {id: 2, comment_body: "Insightful comment"}
  ]
}

store.pushPayload('post', pushData); 

@get('store').pushPayload('organization', data)

json

organizations:[
    {id:1,...},
    {id:2,...},
    {id:3,...}
]
0

All Articles