| 19 | |
| 20 | == Concepts == |
| 21 | |
| 22 | === Dynamic Model Loading === |
| 23 | |
| 24 | While web2py executes ''all'' models during every request cycle, {{{S3Model}}} only executes the models needed to process the request. |
| 25 | |
| 26 | That 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 | |
| 28 | In web2py, database tables can be accessed from the global '''db''' object: |
| 29 | {{{#!python |
| 30 | table = db.my_table |
| 31 | }}} |
| 32 | |
| 33 | In S3, tables must be requested from '''s3db''': |
| 34 | {{{#!python |
| 35 | table = s3db.my_table |
| 36 | }}} |
| 37 | |
| 38 | Model 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 | |
| 40 | S3Models 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 | |
| 42 | It 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'' |