-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cannot query on _cls #450
Comments
Can you explain your usecase? why you have to use |
Because I cannot regularly query on the _cls field, I cannot do Q(_cls="MyClass"). |
I guessed that :) but I'm trying to understand what is failing in the Document definition that forces you have to work around with Can you provide an example on why you need to ? Can't you use the inherited classes which automatically inject _cls into the query? |
Ok, so to explain my usecase: All my users generate Activities. There are several kind of Activities which are all subclasses of the Activity class. Users follow other users and so have all the activities of the user they follow. But they have also all the activities of a certain kind. So I need to make the query: {$or: [{user_id: {$in: [list, of, user, ids]}}, {_cls: "My.Sub.Class"}]}. |
+1 |
I agree I think we could make a Scheduling for 0.9 |
👍 also need this to create filters for content types defined in modules in www.quokkaproject.org, currently I am duplicating that field on .save() method to be able to query. |
to query on this field all you need is to set the parameter class_check to False |
👍 @Reddine |
Hi. @Reddine, is this relevant on MongoEngine 0.10.5? (The context: I'm trying to use flask-mongoengine/WTForms and Document inheritance, and I'm looking for the best way to filter by subclass.)
The link about query on _cls seems outdated.
both raise
And
return what I expect. So,
|
Indeed, I removed the class_check attribute from a query in my application that runs on recent version of mongoengine and I got the same result. using only '_cls' |
Although I'm not in love with the current solution, we can query on
The fix was introduced in #719. |
Hi,
I needed to build a complex query in which I had to add a predicate on the _cls attribute through a naw query:
query |= Q(raw={'_cls': "My.Sub.Class"})
However, because of the construction of the query with a dict, mongoengine overide this part of the query with:
{ "_cls" : { "$in" : ["Class", "Class.SubClass", "and so on"]}}.
I have been able to get around this problem by adding a $or predicate but I think I should not have to do that:
query |= Q(raw={'$or': [{'_cls': "My.Sub.Class"}]})
Thanks for your great work!
The text was updated successfully, but these errors were encountered: