Show
Ignore:
Timestamp:
02/12/07 15:27:25 (7 years ago)
Author:
ged
Message:

- Changed tests so that when one test fails, other unrelated ones don't.

- now options are initialized to their "global defaults" values instead
of hard coded values, so we can set a bunch of options on all entities.

- added a way to set custom column names for belongs_to relations.

- implemented a way to delay setup (to have a behaviour somewhat similar
to something non dynamic). This is to be used in conjunction with the
new "setup_all" function.

- made autoload work for belongs_to/has_one/has_many relations. The user
must provide column names in that case. It would be possible (and quite
easy, I think) to guess things based on foreign keys when there is only
one relation of the same type between two entities, but I haven't done
it yet, and don't plan to do it before the release. It doesn't work yet
for HasAndBelongsToMany relationships.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/__init__.py

    r45 r47  
    3030           'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many',  
    3131           'using_options', 'using_table_options', 'using_mapper_options', 
    32            'create_all', 'drop_all', 'metadata', 'objectstore'] + \ 
     32           'options_defaults', 'metadata', 'objectstore', 
     33           'create_all', 'drop_all', 'setup_all', 'cleanup_all',  
     34           'delay_setup'] + \ 
    3335          sqlalchemy.types.__all__ 
    3436 
    35 __pudge_all__ = ['create_all', 'drop_all', 'metadata', 'objectstore'] 
     37__pudge_all__ = ['create_all', 'drop_all', 'metadata', 'objectstore',  
     38                 'delay_setup', 'setup_all'] 
    3639 
    3740# connect 
     
    6265    for md in metadatas: 
    6366        md.drop_all() 
     67 
     68delayed_entities = set() 
     69delay_setup = False 
     70 
     71def setup_all(): 
     72    '''Setup the table and mapper for all entities which have been delayed. 
     73     
     74    This should be used in conjunction with setting ``delay_setup`` to ``True`` 
     75    before defining your entities. 
     76    ''' 
     77    global delay_setup 
     78    delay_setup = False 
     79    for entity in delayed_entities: 
     80        entity.setup() 
     81    delayed_entities.clear() 
     82    create_all() 
     83 
     84def cleanup_all(): 
     85    drop_all() 
     86    for md in metadatas: 
     87        md.clear() 
     88    metadatas.clear() 
     89    EntityDescriptor.uninitialized_rels.clear() 
     90 
     91    objectstore.clear() 
     92    sqlalchemy.clear_mappers() 
     93