2. You could write
   x = Klass.find(key)
   if x.nil?
     x = Klass.new
     x.save
   end

get_or_new doesn't save, so perhaps Klass.find(key) || Klass.new(key)

Risky (another Ruby Riak model layer) offers Klass.get_or_new(key)

    3. control the bucket on which the document is stored/retrieve
    (using an attribute). From what I've seen, riak uses the class name
    as bucket.

I don't know about Ripple, but in Risky you could:

a.) Override MyModel.bucket to choose different buckets.
b.) Subclass and set MyModel.bucket
c.) Ignore/override MyModel.[] altogether, fetch the robject yourself, and use Klass.from_riak_object.

You should be aware that buckets are essentially key prefixes. When you go to *get* a record, you would need to know the bucket name. Two cases:

Lots of buckets, e.g. one per user: Why not make the username part of the key? It may not feel as clean, but you won't have to fight the ORM as much.

Few buckets, e.g. Record, RecordTypeA < Record, RecordTypeB < Record: Subclass and set/override .bucket.

--Kyle

_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to