-
Notifications
You must be signed in to change notification settings - Fork 133
CouchRest::ExtendedDocument Basic Queries
newacct edited this page Sep 13, 2010
·
3 revisions
class Post < CouchRest::ExtendedDocument use_database DB property :title property :content view_by :title end
Load all documents that have the “couchrest-type” field equal to Post
@all_posts = Post.all p @all_posts
Returns the number of documents that have the “couchrest-type” field equal to Post
@count_posts = Post.count puts @count_posts
Load the first document that have the “couchrest-type” field equal to Post
@first_post = Post.first p @first_post
Load a document from the database by id
#No exceptions will be raised if the document isn't found @post = Post.get("some_doc_id") p @post #An exception will be raised if the document isn't found @post = Post.get!("some_doc_id") p @post
See couchrest/mixins/views.rb for more details
#Load all documents that have the "couchrest-type" field equal to Post and field title @posts = Post.by_title puts "#{@posts.count} posts was found" puts p @posts #Load all documents that have the "couchrest-type" field equal to Post and "a specific title" @posts = Post.by_title(:key => "A specific title") p @posts