Changes between Version 13 and Version 14 of S3/S3Model


Ignore:
Timestamp:
01/20/14 09:02:51 (11 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • S3/S3Model

    v13 v14  
    1717
    1818Data models can be implemented as subclasses of S3Model, and then loaded on demand - with automatic resolution of cross-model dependencies. This saves processing time as it will always only load those models which are actually needed to process the request.
     19
     20== Concepts ==
     21
     22=== Dynamic Model Loading ===
     23
     24While web2py executes ''all'' models during every request cycle, {{{S3Model}}} only executes the models needed to process the request.
     25
     26That means though that all names (e.g. tables, variables, functions) which are defined in S3Models need to be requested explicitly before they can be used. To facilitate that, a global {{{S3Model}}} instance '''s3db''' serves as model loader.
     27
     28In web2py, database tables can be accessed from the global '''db''' object:
     29{{{#!python
     30table = db.my_table
     31}}}
     32
     33In S3, tables must be requested from '''s3db''':
     34{{{#!python
     35table = s3db.my_table
     36}}}
     37
     38Model loading happens ''only'' when a name from this model is requested, i.e. s3db loads no models whatsoever unless names are requested. If the model defining the table (or function, variable etc) has not yet been executed during the request, s3db will do so ''at this point''.
     39
     40S3Models can request other S3Models to be loaded, thereby automatically resolving dependencies. Note that for models where the Eden module is deactivated in the current template, s3db runs the defaults()-method instead of the model()-method (except for mandatory modules). If dependencies between S3Models are circular (i.e. X requesting Y and Y requesting X), S3Model will raise an exception.
     41
     42It is wise to split Eden modules into multiple S3Models - so that dynamic model loading always only loads the necessary minimum for a requested name. However, too excessive splitting can increase loader overheads and the risk of bugs, so tables which are used together most of the time should be kept in the same S3Model.
     43
     44=== Resources ===
     45
     46  ''- tbw''
     47
     48=== Resource Components ===
     49
     50  ''- tbw''
     51
     52=== Resource Configuration ===
     53
     54  ''- tbw''
     55
     56=== Resource Methods ===
     57
     58  ''- tbw''
     59
     60=== Super-Entities ===
     61
     62  ''- tbw''
    1963
    2064== Defining Models ==
     
    57101
    58102The {{{modules/s3db/skeleton.py}}} module is a well-commented skeleton module to explain how things should look like inside an S3 model.
     103
     104 '̈́''Note:''' it is possible (and sometimes even recommendable) to split an s3db module into sub-modules, and then import the names from the sub-modules into the main module.
     105
    59106=== Model Classes ===
    60107
     
    258305}}}
    259306
    260 == Concepts ==
    261 
    262 === Resources ===
    263 
    264   ''- tbw''
    265 
    266 === Resource Components ===
    267 
    268   ''- tbw''
    269 
    270 === Resource Configuration ===
    271 
    272   ''- tbw''
    273 
    274 === Resource Methods ===
    275 
    276   ''- tbw''
    277 
    278 === Super-Entities ===
    279 
    280   ''- tbw''
    281 
    282307----
    283308