db.events.status.requires = IS_IN_DB(db, 'status.id', 'status.status') -Thadeus
On Sun, Oct 18, 2009 at 12:12 AM, Sebastian Brandt <[email protected]>wrote: > > Hi everyone, > I am having a hard time understanding SQL Queries in web2py. > > I have a database layout like that: > > db.define_table( > 'status', > SQLField('status') > ) > db.define_table( > 'severity', > SQLField('severity') > ) > db.define_table( > 'events', > SQLField('host'), > SQLField('message'), > SQLField('datetime_submitted','datetime',default=request.now, > writable=False), > SQLField('status',db.status), > SQLField('severity',db.severity) > ) > > As shown, I use reference in the events table. I have a dropdown-menu > that you can select events of a special status and not see all events. > The IDs of those events are stored in id. > My query I perform to get events back that have a special status is > the following: > > events=db(db.events.id==id).select() # > > The events are printed in the view with a simple {{=events}} > statement. I return exaclty what I have in the db-table, which are > also the IDs of the fields in the referenced tables and not the "text" > of the status and severity. > > Is there a way I can build a query that gives back the entry stored > in .db.status.status and db.status.severity instead of their reference- > id or would you normally match the id given back in events with the > referenced entry while printing it somewhere in the view? > > I am asking because this would mean for the second option, that I have > to do 2 more queries to the db and I would need some kind of loop to > replace the id with the referenced entry and I am really wondering if > this is the most performanced optimize approach. > > Thanks in advance > Sebastian Brandt > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

