Skip to content

Instantly share code, notes, and snippets.

@mschoch
Created October 4, 2012 21:51
Show Gist options
  • Save mschoch/3836715 to your computer and use it in GitHub Desktop.
Save mschoch/3836715 to your computer and use it in GitHub Desktop.
Build options to query for specific author, set to include docs...
irb(main):008:0* opt = { :startkey => ["EmausBot", ""], :endkey => ["EmausBot", "\u9999"], :reduce => false, :include_docs =>true}
=> {:startkey=>["EmausBot", ""], :endkey=>["EmausBot", "香"], :reduce=>false, :include_docs=>true}
Now query with those options
irb(main):009:0> Article.by_author(opt).entries
=> [#<Article id: 11897520>, #<Article id: 13251428>, #<Article id: 13389397>, #<Article id: 1410592>, #<Article id: 1480853>, #<Article id: 15176975>, #<Article id: 15504795>, #<Article id: 18996339>, #<Article id: 19012194>, #<Article id: 20151985>, #<Article id: 2018930>, #<Article id: 25575962>, #<Article id: 25615649>, #<Article id: 2568917>, #<Article id: 25879895>, #<Article id: 2733855>, #<Article id: 27550365>, #<Article id: 2860125>, #<Article id: 3559860>, #<Article id: 363145>, #<Article id: 3728186>, #<Article id: 4450579>, #<Article id: 448686>, #<Article id: 6826539>, #<Article id: 72394>, #<Article id: 9193832>]
Look at the first article returned...
irb(main):010:0> Article.by_author(opt).entries[0]
=> #<Article id: 11897520>
Try to access its contributors...
irb(main):011:0> Article.by_author(opt).entries[0].contributors
=> nil
Access the same article directly using find...
irb(main):012:0> direct = Article.find(11897520)
=> #<Article id: 11897520>
Now try to access the contributors field...
irb(main):013:0> direct.contributors
=> [{"name"=>"EmausBot", "timestamp"=>"2012-01-28T19:40:21Z"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment