You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered: