couchrest / couchrest_model

Doing the simple stuff so you don't have to
Apache License 2.0
305 stars 116 forks source link

CouchRest database per main Entity #4

Closed shenoudab closed 14 years ago

shenoudab commented 14 years ago

Dears, i'm looking for implement in my application to have database for the main entity of the system. i'd like to create and set a database for this entity named with a property value.

Like : For a CMS Project, to create a couchdb database for every Site.

kindly, as that is based on Rest and Rails : in the create method i have the property value, so i can create the database and save the document in side that database. but in the other methods how can i specify the database to get the documents from, in (show, edit, update, delete). and in the index method, how can be enhanced for that scenario (Database per Main Entity).

also, how can i check if there a database with the value i have with creating the database if not exist.

Thanks, Shenouda Bertel

samlown commented 14 years ago

I think I answered this here:

http://github.com/couchrest/couchrest/issues/closed#issue/38

Use the ClassProxy to access models without defining a global database. At some point in the near future I'd like to implement "proxied_by" and "proxies" using a pattern I've used a couple of times now. Until then, you'll just have to do this manually I'm afraid.

You can use the CouchRest.database! method as many times as you like, it is none destructive and will create the database if it does not already exist.

shenoudab commented 13 years ago

Dear Sam,

kindly, i was asking how to use couchrest_model proxy inside a my model to set current_db, where the database specified from request.subdomain.

also, did couchrest_model support block usage as i try to do the following nothing return with around_filter in Application Controller : around_filter :set_entity def set_entity if resource_name == :user User.on(current_db){yield} end end

Thanks, Shenouda Bertel