Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby_class attribute in every document #20

Closed
shenoudab opened this issue May 23, 2010 · 7 comments
Closed

ruby_class attribute in every document #20

shenoudab opened this issue May 23, 2010 · 7 comments

Comments

@shenoudab
Copy link

Hi,
couchdb document have attribute "ruby_class" in every and each document ..
while every database have and represent one model document

as in blog example the database represent model "Post" which have the attribute "comments" represent Comment Model .. why adding "ruby_class" in every Post and every Comment.

@langalex
Copy link
Owner

without the ruby_class we don't know which class to use when converting the document into a ruby object. also, you can't do things like finding all blog posts without knowing wether a particular document is a blog post or not.

@shenoudab
Copy link
Author

but what if every database have only one Model. as say that this database have documents which represent "Post" Model.
so when converting to Ruby Object i know that i will convert them to Post Model.
and also finding Posts, as every document in that database is represent a Post Model ....

@langalex
Copy link
Owner

do you have any specific reason to put every kind of document into a separate database? if not you might find your mindset stuck in SQL land... anyway if you have reasons to do so, then you can overwrite the to_hash method in CouchPotato and filter out the ruby_class attribute.

@shenoudab
Copy link
Author

thanks for your support ... as i will have a database to represent one Model.. the core model.

but i'd like to ask .. is overwriting the to_hash method ... will not write the "ruby_class" in the document and also the dynamic views ..

@langalex
Copy link
Owner

i don't know what you are talking about, can you rephrase your question?

@shenoudab
Copy link
Author

sorry, i'd like to ask how to ignore write the ruby_class property in the document.
and also ignore represent the ruby_class in dynamic views offered by couch_potato.

is overwriting to_hash method will cover the above.

@langalex
Copy link
Owner

def to_hash
  hash = super.dup
  hash.delete('ruby_class')
  hash
end

the auto generated view all check for the ruby_class, so you have to provide your own map function:

view :my_view, :type => :custom, :map => "function(doc) {emit(...)}"

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants