riak-ripple / ripple

A rich Ruby modeling layer for Riak, Basho's distributed database
Other
618 stars 152 forks source link

Dynamically find/save a document in a different bucket #311

Closed weiser closed 11 years ago

weiser commented 11 years ago

Summary

There are times when I would like to save multiple versions of a Ripple Document. Ideally, I would like each version of the document to be in its own bucket.

E.g. if I have the following class definition:

class A
  include Ripple::Document

  self.bucket_name = 'A'

  property :thing1, String
end

and I would like to create two A objects, but save them in different buckets:

a1 = A.new()
a1.thing1 = "hi"
a1.key = 'a'
a1.save! # saves in bucket 'A'

a2 = A.new()
a2.thing1 = "mom"
a2.key = 'a'
a2.save_in_bucket!('B') # saves in bucket 'B'

I would also like the ability to load documents from buckets dynamically:

a2 = A.find_in_bucket('B') 

Is there a way to do this currently, or should I add a PR?

Settings

git://github.com/basho/ripple.git@ rev: f866ddd5e2b0a11bb11bd29683f4f41f5c1bca22

weiser commented 11 years ago

After thinking about it overnight, I think a better way of achieving my goal would be to subclass the document model and modify the bucket_name of the subclass.

cmeiklejohn commented 11 years ago

Yes. I think that sounds like the right approach.

Also, IIRC, bucket_name can also be implemented as a method in your class as well if that also helps.