Couchdb finder using CouchRest
-
30-06-2021 - |
题
I just want to know how can I build a find_all_by_action_and_author_id method in Rails with while using the couchdb. My Model looks like this:
class Activity < CouchRest::Model::Base
property :action, String
property :author_id, String
end
if I try to build a View like that:
design do
view :by_action_and_author_id
end
I dont know how to get the right result, I tried it with this:
Activity.by_action_and_author_id(:keys => [['action','foo'], ['author_id', '1']]).all
But the result is always a empty hash. What is the best way to do this? Any examples?
With PostgreSQL it would look like this
Activity.where(action: 'foo', author_id: '1').all
it cant be so complicated
Thanx
解决方案
have a look at the generated couchdb-view! you can see which keys get emitted. there is no thing as a mapping there, so i think that [['action','foo'], ['author_id', '1']]
should be just ['foo', '1']
.
i do not know for sure how couchrest-models handles views, but you can find more infos here: http://www.couchrest.info/model/view_objects.html
have a look at the tag-example.