Hello,
I'm pretty new in web2py, and I've got a problem while trying to get
the results of 'belongs' query.
My aim is to use list:reference to make a many-to-one relationship.
Below is a sample controller I tried to run with both web2py-current
and web2py-nightly and with GAE as storage backend.
def index():
# define tables
db.define_table('dog',
Field('name'),
)
db.define_table('person',
Field('name'),
Field('dogs', 'list:reference dog'),
)
db(db.dog.id > 0).delete()
db(db.person.id > 0).delete()
# insert data
dogs = []
dogs.append(db.dog.insert(name="Pluto"))
dogs.append(db.dog.insert(name="Buddy"))
person_id = db.person.insert(name="Massimo", dogs=dogs)
# select data
person = db.person(person_id)
dogs = db(db.dog.id.belongs(person.dogs)).select()
return "My dogs: " + ", ".join(d.name for d in dogs)
Instead of getting "My dogs: Pluto, Buddy", I see an exception
Traceback (most recent call last):
File ".../web2py/gluon/restricted.py", line 188, in restricted
exec ccode in environment
File ".../web2py/applications/myapp/controllers/default.py:index",
line 28, in <module>
File ".../web2py/gluon/globals.py", line 95, in <lambda>
self._caller = lambda f: f()
File ".../web2py/applications/myapp/controllers/default.py:index",
line 25, in index
File ".../web2py/gluon/dal.py", line 4507, in select
return self.db._adapter.select(self.query,fields,attributes)
File ".../web2py/gluon/dal.py", line 2677, in select
(items, tablename, fields) =
self.select_raw(query,fields,attributes)
File ".../web2py/gluon/dal.py", line 2637, in select_raw
filters = self.expand(query)
File ".../web2py/gluon/dal.py", line 2548, in expand
return expression.op(expression.first, expression.second)
File ".../web2py/gluon/dal.py", line 2595, in BELONGS
return
[GAEF(first.name,'in',self.represent(second,first.type),lambda a,b:a
in b)]
File ".../web2py/gluon/dal.py", line 2325, in represent
obj = long(obj)
TypeError: long() argument must be a string or a number, not 'list'
Can someone please explain me what I'm doing wrong. Probable it's a
web2py bug, possibly related with Issue 149 <http://code.google.com/p/
web2py/issues/detail?id=149>.
Thanks in advance.
Roman