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

CouchPotato is not saving nil attributes - This breaks the default views #12

Closed
jweiss opened this issue Dec 1, 2009 · 2 comments
Closed

Comments

@jweiss
Copy link
Contributor

jweiss commented Dec 1, 2009

CouchPototo discards nil attributes before saving, thus removing these attributes from the JSON document. Apart from being not what I expect (I did specify the attribute as a property, and the property is nil. But still it is a property), it breaks the query views (or better said, the map function):

class User
include CouchPotato::Persistence

property :name

view :by_name, :key => :name
end

:name is optional here, but this results in an exception in CouchDB if you have users with no name:

User.find_by_name('foo')

The problem is the map function:

emit(doc['name'], null)

doc['name'] is undefined which raises a JSON serialization exception.

I think the correct way is to store the nil attribute as null. This way the above map function works as expected and the JSON document looks as expected.

I've fixed it here:

http://github.com/jweiss/couch_potato/commit/9e8fce04656d1d86793b276a34f66336d89166e5

Jonathan

@roidrage
Copy link
Contributor

roidrage commented Dec 2, 2009

I made jweiss' test a bit more rspec-like over here: http://github.com/mattmatt/couch_potato/commits/issue_12

@langalex
Copy link
Owner

i've pulled this fix in a while ago

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

3 participants