amco / dolly

Not an ORM for CouchDB in rails.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow setting a custom method/property as the primary key (_id)

rubenrails opened this issue · comments

Currently, there are a couple of ways of achieving this, either by overriding the id method entirely, or by using a callback (e.g. before_save).

It'd be better if we could do something like:
Option A)

class Product < Dolly::Document
  property :sku, primary: true
end

Option B)

class Product < Dolly::Document
  property :sku

  primary :sku
end
p = Product.new
p.sku = "sau101"
p.id # "product/sau101"

It should work with either document propertys or arbitrary instance methods.

I prefere option "A", also, maybe explicitly override the "namespace" of the document which will sometimes differ from the class one, specially if we are using inheretance,

This is an interesting feature to add. I shall ponder these ideas further

I think this is also a feature and should not be included in 1.0 stable