Thank you guys, i just got it :) Mengu
On Nov 1, 3:35 am, Yarko Tymciurak <[email protected]> wrote: > ...you really want to understand the stateless nature of the web, and > the flow thru web2py in response to a request: > > someone requests a page from your web2py (e.g. types a URL); > > web2py parses the request (gluon) and decides which application and > controller this is for > > web2py sets up the environment for the call (i.e. spawns a thread, and > runs all the application's model files - which is how that thread gets > a db connection, and knows what tables exist) > > web2py then calls the appropriate controller (with this env setup) > with any parameters (as the request URL might indicate) > > NOW - that note about multiple def'ns of a connection (ortable) > should make more sense. > > - Yarko > > On 10/31/09, Thadeus Burgess <[email protected]> wrote: > > > Ok, models are executed in alphabetical order. And you only need to define > > the DAL once, if you do it again, you lose all tables defined. > > > so this is the order they would get executed in. > > > comment.py <<< > > > db.py <<< > > > post.py <<< > > > -Thadeus > > > On Sat, Oct 31, 2009 at 6:56 PM, Mengu <[email protected]> wrote: > > >> Thadeus, thanks for the reply. By the way, these are not controllers, > >> these are models. > > >> Mengu > > >> On Nov 1, 1:53 am, Thadeus Burgess <[email protected]> wrote: > >> > 2) YES, They need to be in db.py, or another model file, but preferably > >> > db.py. > > >> > 1) will not work. controllers are not python modules, they cannot be > >> > imported. They are ment to be run in a pre-setup environment by web2py. > > >> > The DAL does not know about any tables in the database, unless they are > >> > specified with "define_table"... Even for tables that exist. > > >> > So you cannot split your dbtablestatements up into separate > >> controllers, > >> > that get called at separate times. > > >> > -Thadeus > > >> > On Sat, Oct 31, 2009 at 4:07 PM, Mengu <[email protected]> wrote: > > >> > > Hi everyone. > > >> > > I have db = DAL("sqlite://blog.db") in my db.py. I can define my > >> > > tables in my models with having that statement in the model however I > >> > > cannot create relationships. > > >> > > For example, this is post.py: > >> > > db = DAL("sqlite://blog.db") > >> > > db.define_table('post', > >> > > Field('title', 'string'), > >> > > Field('body', 'text') > >> > > ) > > >> > > and this is comment.py: > >> > > db = DAL("sqlite://blog.db") > >> > > db.define_table("comment", > >> > > Field('post_id', db.post), > >> > > Field('author', 'string'), > >> > > Field('comment', 'text') > >> > > ) > > >> > > I get the following error: > > >> > > Traceback (most recent call last): > >> > > File "/home/mengu/projects/web2py/gluon/restricted.py", line 184, in > >> > > restricted > >> > > exec ccode in environment > >> > > File "/home/mengu/projects/web2py/applications/blog/models/ > >> > > comment.py", line 5, in <module> > >> > > Field('post_id', db.post), > >> > > File "/home/mengu/projects/web2py/gluon/sql.py", line 1148, in > >> > > __getattr__ > >> > > return dict.__getitem__(self,key) > >> > > KeyError: 'post' > > >> > > I also should note that this works fine if post_id is not db.post but > >> > > an integer or another field. > > >> > > So my questions are: > > >> > > 1) Should I import db.post for this to work and how? > > >> > > 2) Musttabledefinitionsalways be made on the db.py file? > > >> > > Thanks. > > >> > > Mengu --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

