namlook/mongokit — Issue #81: @classmethod not working
Author: nomulous
Created: 2012-02-12 19:15:04+00:00
State: open

I have the following code, with a class method.

@connection.register
class User(Document):
__collection__ = 'users'
structure = {
'id': int,
'screen_name': unicode,
'token': unicode,
'secret': unicode,
}

use_dot_notation = True

@classmethod
def create_or_update_by_id(cls, id, screen_name, token, secret):
print (cls, cls())
user = cls.find_one({'id': id}) or cls()

user.id = id
user.screen_name = screen_name
user.token = token
user.secret = secret

user.validate()

return user

But when I call it, with `db.User.create_or_update_by_id(...)` I get the following error:

`TypeError: unbound method find_one() must be called with CallableUser instance as first argument (got mongo_query instance instead)`

In other ORMs this works. Do class methods not work in MongoKit, or am I doing something wrong?