On Fri, Sep 11, 2009 at 4:03 AM, Fran <[email protected]> wrote:
> > On Sep 11, 8:28 am, wf321 <[email protected]> wrote: > > I still not understand why table define in model/db.py only need > > define once, then all sub-sequence requests can access it without > > execute db.define_table at every request > > The models get executed in every request. > ...this has come up before, so let's see if we can put the correct abstraction on this: a db.define_table() is a Python data structure creating _kind of_ thing; it does not define or create tables (unless migrations are set, and the record of what the table definition is in the db differs from what the web2py code - eg the define_table() - thinks it is). So "define table" is no more than a declaration, sort of like this _kind of_ thing (excuse my C roots for the moment, and the literary liberties I take with even that): struct table { char* table_name; int id; field_name[0] = "user_name"; field_type[0] = "string"; field_name[1] = "some_foreign_key"; field_type[1] = "reference other_table_name"; .... } That, in effect, is all the db.define_table is - web2py's declaration of a particular table's structure (albeit run time, still rather trivial). Hope this helps a bit. > > >, but table define in > > default.py need execute db.define_table at every request. > > I guess you're talking about controllers/default.py - these will only > get executed when the default controller is run (if outside of > functions) or if a fucntion is called (if inside). > Won't be visible to any other controllers. > > Suggest reading the manual to see program flow. > If you can't afford the manual then the cookbook has this too: > http://www.scribd.com/doc/16085263/web2py-slides-version-163 > > F > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

