2013-03-06 13 views
5

Emberに特定のモデルのカスタムREST URLを設定する方法はありますか?このモデルと同様特定モデルのカスタムREST URL

App.Post = DS.Model.extend({ 
    title: DS.attr('string'), 
    comments: DS.hasMany('App.Comment') 
}); 
App.Comment = DS.Model.extend({ 
    content: DS.attr('string'), 
    post: DS.belongsTo('App.Post') 
}); 

そして、このお店:

app.Store = DS.Store.extend({ 
    revision : 11, 
    adapter : DS.RESTAdapter.extend({ 
     namespace : 'rest' 
    }) 
}); 

私はコメントはデフォルトの動作である代わりに/rest/comments/rest/post/{id}/comments経由で取得していることを望みます。
特定のモデルに対してrest-urlを設定することはできますか?

+0

私はこの事件についてのgithubの問題を発見した:post.jsモデルファイルに直接https://github.com/emberjs/data/issues/186 –

答えて

1

これは文字通り、あなたのアプリケーション全体で1つのモデルのためのものか、これはあなたのRESTバックエンドが使用するデフォルトの "hasMany" URIですか?私はapi(django rest framework)がこの正確なuriを使用していて、ember-dataプロジェクトのフルブロープル要求を必要としているのは、アダプタに関連する "親"または "所有者"それが存在しなかったために必要な)。

私は独自のアダプタを作成しています(ベースアダプタをサブクラス化して、異なるhasManyをオーバーライドするだけです)。私が私のアダプタのために書いた方法は以下の通りです。ここで私の本格的なアダプタを参考にしています。

これは、あなたのモデルに追加のアダプタと「スコープ」に登録することができます11優しいところで(まだ12にアップグレードしていない)

https://github.com/toranb/ember-data-django-rest-adapter/blob/master/tests/adapter.js

findMany: function(store, type, ids, parent) { 
     var json = {} 
     , root = this.rootForType(type) 
     , plural = this.pluralize(root) 
     , ids = this.serializeIds(ids) 
     , url = this.buildFindManyUrlWithParent(store, type, ids, parent); 

     this.ajax(url, "GET", { 
      success: function(pre_json) { 
       json[plural] = pre_json; 
       Ember.run(this, function(){ 
        this.didFindMany(store, type, json); 
       }); 
      } 
     }); 
    }, 
2

燃えさしデータ修正です。

App.Store.registerAdapter('App.Post', DS.RESTAdapter.extend({ 
    url: "/rest/post/" 
})); 
+0

?ありがとう。 – Soullivaneuh

関連する問題