Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduced range_from so that no full startkey needs to be specified.

  • Loading branch information...
commit abaceb58dcc256e3ca798d171bc45c08d9456436 1 parent e20a1fb
Mathias Meyer roidrage authored
4 lib/simply_stored/couch/has_many.rb
View
@@ -9,7 +9,7 @@ def define_has_many_getter(name, options)
define_method(name) do |*args|
local_options = args.first && args.first.is_a?(Hash) && args.first
if local_options
- local_options.assert_valid_keys(:force_reload, :with_deleted, :limit, :order, :startkey_docid, :endkey_docid, :endkey, :startkey)
+ local_options.assert_valid_keys(:force_reload, :with_deleted, :limit, :order, :range_from, :range_to, :endkey, :startkey, :endkey_docid, :startkey_docid)
forced_reload = local_options.delete(:force_reload)
with_deleted = local_options[:with_deleted]
limit = local_options[:limit]
@@ -21,7 +21,7 @@ def define_has_many_getter(name, options)
descending = false
end
- view_options = {:with_deleted => with_deleted, :limit => limit, :descending => descending, :foreign_key => options[:foreign_key]}.update((local_options || {}).reject {|key, value| ![:startkey, :endkey, :startkey_docid, :endkey_docid].include?(key)})
+ view_options = {:with_deleted => with_deleted, :limit => limit, :descending => descending, :foreign_key => options[:foreign_key]}.update((local_options || {}).reject {|key, value| ![:startkey, :endkey, :range_from, :range_to, :startkey_docid, :endkey_docid].include?(key)})
cached_results = cached_results = send("_get_cached_#{name}")
cache_key = _cache_key_for(local_options)
if forced_reload || cached_results[cache_key].nil?
3  lib/simply_stored/instance_methods.rb
View
@@ -183,10 +183,11 @@ def find_associated(from, to, options = {})
view_options[:startkey] = ["#{id}", {}]
view_options[:endkey] = [id]
else
- view_options[:startkey] = options[:startkey] || [id]
+ view_options[:startkey] = options[:startkey] || (options[:range_from] ? [id, options[:range_from]] : [id])
view_options[:endkey] = options[:endkey] || ["#{id}", {}]
end
view_options[:limit] = options[:limit] if options[:limit]
+
view_options.update(options.reject{|key, value| ![:startkey_docid, :endkey_docid].include?(key)})
if options[:with_deleted]
4 test/couchdb/couch_has_many_test.rb
View
@@ -374,8 +374,6 @@ class CouchHasManyTest < Test::Unit::TestCase
@user = User.create(:title => "Mr.", :_id => 'one')
@post = Post.create(:user => @user, :_id => 'two')
@post2 = Post.create(:user => @user, :_id => 'four')
- @post2.created_at = Time.now + 2
- @post2.save!
end
should "allow options to specify start and end document ids" do
@@ -389,7 +387,7 @@ class CouchHasManyTest < Test::Unit::TestCase
should "fetch documents starting at the specified id" do
@user2 = User.create(:title => 'Mrs.')
@post3 = Post.create(:user => @user2)
- posts = @user.posts(:startkey_docid => @post.id, :startkey => [@user.id, @post.created_at])
+ posts = @user.posts(:range_from => @post.created_at, :startkey_docid => @post.id)
assert_equal 1, posts.size
assert_equal @post, posts.first
end
Please sign in to comment.
Something went wrong with that request. Please try again.