Field('room','references room'),
should be
Field('room', db.room),
On Nov 7, 3:39 pm, Limedrop <[email protected]> wrote:
> A couple of obvious thing. First, the query goes with the db() not
> the select(). Second, the reference to room is via room.id rather
> than room.name. So you could try:
>
> reservations = db(db.reservation.room==room.id).select()
>
> On Nov 8, 8:49 am, Matthew Young <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello I am using the Version 1.99.3 (2011-11-07 17:41:19) dev version
> > of web2py.
>
> > I am having an issue with this view function:
> > def check_room_availability():
> > room = db.room(request.args(0)) or redirect(URL('view_rooms'))
> > reservations = db().select(db.reservation.room.name==room.name)
> > return dict(room=room, reservations=reservations)
>
> > I get the following error when this page is viewed with a room number
> > passed as an argument:
> > Traceback (most recent call last):
> > File "/home/mattosaurus/web2py/gluon/restricted.py", line 194, in
> > restricted
> > in code it raises a RestrictedError containing the traceback.
> > layer is
> > File "/home/mattosaurus/web2py/applications/roomReserve/controllers/
> > default.py", line 121, in <module>
> > File "/home/mattosaurus/web2py/gluon/globals.py", line 149, in
> > <lambda>
> > self.files = [] # used by web2py_ajax.html
> > File "/home/mattosaurus/web2py/applications/roomReserve/controllers/
> > default.py", line 85, in check_room_availability
> > reservations = db().select(db.reservation.room.name==room.name)
> > File "/home/mattosaurus/web2py/gluon/dal.py", line 5697, in select
> > db,
> > File "/home/mattosaurus/web2py/gluon/dal.py", line 1225, in select
> > sql_t += ' %s %s' % (icommand, str(t))
> > File "/home/mattosaurus/web2py/gluon/dal.py", line 1128, in _select
> > tablenames = self.tables(query)
> > SyntaxError: Set: no tables selected
>
> > My table definitions in db.py look like this:
> > db.define_table('room',
> > Field('name'),
> > Field('description','text'),
> > Field('location','text'),
> > format='%(name)s')
>
> > db.define_table('reservation',
> > Field('room','references room'),
> > Field('start_date','datetime'),
> > Field('end_date','datetime'),
> > Field('special_requirements','text'),
> > Field('approved','boolean'),
> > auth.signature)
>
> > db.reservation.room.requires = IS_IN_DB(db,db.room.id,'%(name)s')
> > db.room.name.requires = IS_NOT_EMPTY()
> > db.room.description.requires = IS_NOT_EMPTY()
> > db.room.location.requires = IS_NOT_EMPTY()
> > db.reservation.start_date.requires = IS_NOT_EMPTY()
> > db.reservation.end_date.requires = IS_NOT_EMPTY()
>
> > Has anyone seen this error before? Is my select incorrect? I am
> > finding the documentation a little confusing in this area.