我只想知道在使用couchdb的同时,如何在Rails中构建find_all_by_action_and_author_id方法。我的模型看起来像这样:
class Activity < CouchRest::Model::Base
property :action, String
property :author_id, String
end如果我尝试构建一个这样的视图:
design do
view :by_action_and_author_id
end我不知道如何得到正确的结果,我尝试了一下:
Activity.by_action_and_author_id(:keys => [['action','foo'], ['author_id', '1']]).all但是结果总是一个空的散列。做这件事最好的方法是什么?有什么例子吗?
如果使用PostgreSQL,它将如下所示
Activity.where(action: 'foo', author_id: '1').all不可能这么复杂
谢谢
发布于 2012-09-06 02:59:59
看一下生成的couchdb-view!您可以看到发射了哪些键。那里没有映射的东西,所以我认为[['action','foo'], ['author_id', '1']]应该只是['foo', '1']。
我不确定couchrest-models是如何处理视图的,但你可以在这里找到更多信息:http://www.couchrest.info/model/view_objects.html
看一下标记示例。
https://stackoverflow.com/questions/12284870
复制相似问题