langalex / couch_potato

Ruby persistence layer for CouchDB.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CouchPotato.database.load_document does not instantiate the correct class

pawurb opened this issue · comments

Hello. I execute the following commands:

CouchPotato::Config.database_name = 'couch_db_name'
user = User.new(_id: 'uniq_id', name: 'test_user')
CouchPotato.database.save_document user
result = CouchPotato.database.load_document(user._id)
result.class => CouchRest::Document

According to the docs the result object should be of class User (the one that includes CouchPotato::Persistence module). I am new to non relational databases. Please let me know if I am doing something wrong.

what does your user class look like?

converting JSON back to ruby classes is actually done by the json gem. maybe some other gem is messing with that. can you check what JSON.create_id returns? should be 'ruby_class'.

JSON.create_id returns a "ruby_class" string. My User class looks like this:

class User
  include CouchPotato::Persistence

  property :name
end

Sorry I'm not really sure how to help you. Can you post your entire/simplified code in a gist or so so I can reproduce the problem?

Please check out this barebones rails project repo with only couch_potato gem and User class added https://github.com/pawurb/couch_potato_issue. You can replicate my issue with the following commands:

CouchPotato::Config.database_name = 'test'
u = User.new(_id: 'uniq_id', name: 'test_user')
CouchPotato.database.save_document u
result = CouchPotato.database.load_document 'uniq_id'
result.class => CouchRest::Document

I will be greatful for any clue on that.

you are using version 0.7.1, the current version is 1.4.0

That explains a lot. Thanks !