Merge branch 'model-first' of git://github.com/mattetti/couchrest into mattetti/model-first
This commit is contained in:
commit
7430dc17ea
|
@ -109,7 +109,7 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load all documents that have the "couchrest-type" field equal to the
|
# Load all documents that have the "couchrest-type" field equal to the
|
||||||
# name of the current class. Take thes the standard set of
|
# name of the current class. Take the standard set of
|
||||||
# CouchRest::Database#view options.
|
# CouchRest::Database#view options.
|
||||||
def all opts = {}, &block
|
def all opts = {}, &block
|
||||||
self.design_doc ||= Design.new(default_design_doc)
|
self.design_doc ||= Design.new(default_design_doc)
|
||||||
|
@ -119,6 +119,17 @@ module CouchRest
|
||||||
view :all, opts, &block
|
view :all, opts, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Load the first document that have the "couchrest-type" field equal to
|
||||||
|
# the name of the current class.
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# Object:: The first object instance available
|
||||||
|
# or
|
||||||
|
# Nil:: if no instances available
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# opts<Hash>::
|
||||||
|
# View options, see <tt>CouchRest::Database#view</tt> options for more info.
|
||||||
def first opts = {}
|
def first opts = {}
|
||||||
first_instance = self.all(opts.merge!(:count => 1))
|
first_instance = self.all(opts.merge!(:count => 1))
|
||||||
first_instance.empty? ? nil : first_instance.first
|
first_instance.empty? ? nil : first_instance.first
|
||||||
|
|
Loading…
Reference in a new issue