-
Notifications
You must be signed in to change notification settings - Fork 76
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
query not filtering on modelType #168
Comments
Using query with only the 'author' as a selector is a known bug: pouchdb-community/relational-pouch#73 But the query that is used to get the entries for the hasMany should work with a better query that does restrict by type (filter on id). I'll try to see if I can reproduce this, but this should be covered by the test suite. Maybe you could build a ember twiddle? |
Thanks for the quick feedback. I had searched around to see if this was an existing issue before submitting, but did not find any results. I'll try and create a Twiddle, but I don't see ember-pouch hosted on a CDN to add as a dependency. Is it possible to build my query to filter on ID as well? I'm thinking of just adding a |
If you use Ember Twiddle, @eneuhauser, you can put dependencies in the |
You can see the code for querying by type here: https://github.com/nolanlawson/relational-pouch/blob/master/lib/index.js#L426 |
I appreciate @jlami and @backspace help. I did not expect such quick turnaround. I was able to add the ember-pouch addon to Twiddle. The last time I tried to make a Twiddle with an external dependency, I don't think that was possible. Knowing how to do that will be useful in the future. Before trying the Twiddle, I pulled down the ember-pouch code and found an existing test that shows that async I was able to get query: function(store, type, query) {
this._init(store, type);
var recordTypeName = this.getRecordTypeName(type);
var db = this.get('db');
var queryParams = {
selector: this._buildSelector(query.filter)
};
queryParams.selector['_id'] = this._buildDocIDTypeSelector(recordTypeName);
if (!Ember.isEmpty(query.sort)) {
queryParams.sort = this._buildSort(query.sort);
}
return db.find(queryParams).then(pouchRes => db.rel.parseRelDocs(recordTypeName, pouchRes.docs));
},
_buildDocIDTypeSelector(recordTypeName) {
var makeDocID = this.get('db').rel.makeDocID;
return {
'$gt': makeDocID({ type: recordTypeName }),
'$lt': makeDocID({ type: recordTypeName, id: {} })
};
}, Would it be useful to make a pull request with this change? |
A PR for the fix in query is certainly welcome. Though I'm wondering if this should not be moved down to relational-pouch, since that is the layer that is actually in charge of the mapping to types. In my eyes it should have a query function of it's own that ember-couch should call. Did you have any success in making a twiddle that reproduces your initial problem with hasMany? I'm still very curious where this comes from. You are right that there are tests that work with |
@eneuhauser @guillett Perhaps relational-pouch it the place to fix this. See also pouchdb-community/relational-pouch#73 |
+1 this needs to be fixed If I query posts by their name, why am I also receiving users by their name? |
@eneuhauser So... I was bitten by this unexpected behaviour and it took a while to realize it was being caused by the wrong records being retrieved by my query statements. I just grabbed your code above and pasted it into my application adatapber, and it seems like that did the trick. I'm just going to leave your code in place in my adapter until I see an update from the addon itself. Thanks for sharing! |
See also pouchdb-community/relational-pouch#3 |
Unfortunately this approach might cause unexpected results due to a bug in CouchDB: apache/couchdb#816 |
Wouldn't that be true for any index with |
When I call
get
on anasync
hasMany
relationship that isn't loaded, I do not get the related models back. To get around this, I tried callingquery
filtering on thebelongsTo
attribute, but I'm getting back additional models that also have the samebelongsTo
relationship as the model type I queried.If I have a model structure like the following:
With just the
author
loaded and I callauthor.get('comments')
, I do not get back any results. If I call:I will also get back posts for the author, but they will be loaded in the store as
comment
and thetext
attribute will beundefined
.Additional information, I'm using the
dontsavehasmany
flag, ember-pouch 4.2.3, and ember-data 2.10 (and 2.11.0-beta.1).The text was updated successfully, but these errors were encountered: