Zatvobor / ember-couchdb-kit

An Ember.js adapter for Apache CouchDB
MIT License
43 stars 13 forks source link

Change findAll to not assume existence of an "all" _view. #85

Closed blainehansen closed 11 years ago

blainehansen commented 11 years ago

In findAll of document-adapter.js, there is an assumption that users have an "all" _view. This is strange to me, since findMany is implemented with the _all_docs?include_docs=true addition, and it seems findAll should do similarly, since it would be more robust and have out of the box support for any couch configuration.

OpakAlex commented 11 years ago

Hello, findMany search documents by ids. findMany as a query with params, in couchdb this is view.

blainehansen commented 11 years ago

Ah, you saying that makes me think the code is written backwards. Here's the return for findMany:

return this.ajax('_all_docs?include_docs=true', 'POST', normalizeResponce, { data: data });

and here's the return for findAll:

return this.ajax('_design/%@/_view/%@'.fmt(designDoc, typeViewName), 'GET', normalizeResponce, { data: data });

It seems to me those functionalities should be switched. findAll should use the _all_docs?include_docs=true and findMany should use the _design/%@/_view/%@'.fmt(designDoc, typeViewName).

I'm saying this in the first place because in my code, return this.get('store').find('thing'); creates a 404 request because I don't have an all view, and frankly, I shouldn't have to since I'm not doing anything fancy at this point.

OpakAlex commented 11 years ago

lets see: findMany: function(store, type, ids) { We have ids as params from ember-data when use relations.

findAll - find all for type, this means GET request as http://server/things/index In couchdb you can use view for type. In ember-couchdb-kit we name this view as all in typed design document.

blainehansen commented 11 years ago

Hm, then why isn't it working? I have this error thrown:

GET http://localhost/_couch/things/_design/thing/_view/all?include_docs=true&key=%22thing%22 404 (Object Not Found) screenshot from 2013-10-29 13 34 26

OpakAlex commented 11 years ago

GET http://localhost/_couch/things/_design/thing/_view/all?include_docs=true&key=%22thing%22 404 You have 404 error from server. Create desing document step by step as http://wiki.apache.org/couchdb/HTTP_view_API#Creating_Views

OpakAlex commented 11 years ago

You can check this example https://github.com/roundscope/ember-couchdb-kit/blob/master/spec/coffeescripts/document-adapter_spec.coffee#L222-L225