couchrest / couchrest_extended_document

Extends CouchRest with helpers and such
Apache License 2.0
24 stars 5 forks source link

ExtendedDocument views don't return documents with database set #9

Open tapajos opened 14 years ago

tapajos commented 14 years ago

Issue from: http://github.com/couchrest/couchrest/issues#issue/6

I'm not using the use_database(db) command in my ExtendedDocuments (just because I don't like globals that much). So I use :database => @db when accessing my views, but the ExtendedDocuments that are returned don't have their 'database' set, so I can't save or destroy them.

I have a patch if you want it, although I've only been using couchrest for a couple of days so I'm probably missing something...

samlown commented 14 years ago

The safest bet when doing this is to use the class proxy, that should automatically assign the database when the document is loaded.

Something I've had on my mind and I've yet to implement, is to add a "proxied_by" class method to the models. The idea would be that you define a Proxy model and add to it child models you'd like to load, eg "proxy_for :projects". To load you're projects you'd use an instance of your proxy and call: @company.projects, couchrest would handle the rest. If I manage to do this, it'll probably go into CouchRest Model.