Show
Ignore:
Timestamp:
03/05/07 18:03:08 (7 years ago)
Author:
ged
Message:

- Added support for autoloading/reflecting databases with

has_and_belongs_to_many relationships. The tablename argument is now
optional, but still recommended, otherwise you'll have to use the same exact
name for your intermediary table than the one generated.

- Made the colname argument optional for belongs_to relationships in

autoloaded entities. It is only required to specify it if you have several
belongs_to relationships between two entities/tables.

- Fixed bug preventing having entities without any statement.
- Made some PEP8 tweaks in many places. Used the pep8 script provided with

Cheesecake.

- Foreign key names generated by belongs_to relationships use column names

instead of relation names in case we have a relation with the same name
defined in several entities inheriting from the same entity using single-
table inheritance (and we set a custom column name in one of them to avoid
a column-name conflict).

- Actually make the code python 2.3 compatible (Robin's patch was based on

0.1.0 while I had introduced more decorators in the trunk in the mean time).

- Some cleanup/useless code removal (namely the foreign_key stuff in

relationships).

Files:
1 modified

Legend:

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

    r73 r82  
    11''' 
    22Elixir package 
    3      
     3 
    44A declarative layer on top of SQLAlchemy, which is intended to replace the 
    55ActiveMapper SQLAlchemy extension, and the TurboEntity project.  Elixir is a 
    6 fairly thin wrapper around SQLAlchemy, which provides the ability to define  
    7 model objects following the Active Record design pattern, and using a DSL  
     6fairly thin wrapper around SQLAlchemy, which provides the ability to define 
     7model objects following the Active Record design pattern, and using a DSL 
    88syntax similar to that of the Ruby on Rails ActiveRecord system. 
    99 
    10 Elixir does not intend to replace SQLAlchemy's core features, but instead  
     10Elixir does not intend to replace SQLAlchemy's core features, but instead 
    1111focuses on providing a simpler syntax for defining model objects when you do 
    1212not need the full expressiveness of SQLAlchemy's manual mapper definitions. 
     
    3131    from sets import Set as set 
    3232 
    33 __all__ = ['Entity', 'Field', 'has_field', 'with_fields',  
    34            'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many',  
     33__all__ = ['Entity', 'Field', 'has_field', 'with_fields', 
     34           'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many', 
    3535           'using_options', 'using_table_options', 'using_mapper_options', 
    3636           'options_defaults', 'metadata', 'objectstore', 
    37            'create_all', 'drop_all', 'setup_all', 'cleanup_all',  
     37           'create_all', 'drop_all', 'setup_all', 'cleanup_all', 
    3838           'delay_setup'] + \ 
    3939          sqlalchemy.types.__all__ 
     
    5151    # thread local SessionContext 
    5252    class Objectstore(object): 
     53 
    5354        def __init__(self, *args, **kwargs): 
    5455            self.context = SessionContext(*args, **kwargs) 
     56 
    5557        def __getattr__(self, name): 
    5658            return getattr(self.context.current, name) 
    5759        session = property(lambda s:s.context.current) 
    58      
     60 
    5961    objectstore = Objectstore(sqlalchemy.create_session) 
    6062 
    6163metadatas = set() 
     64 
    6265 
    6366def create_all(): 
     
    6568    for md in metadatas: 
    6669        md.create_all() 
     70 
    6771 
    6872def drop_all(): 
     
    7478delay_setup = False 
    7579 
     80 
    7681def setup_all(): 
    7782    '''Setup the table and mapper for all entities which have been delayed. 
    78      
     83 
    7984    This should be used in conjunction with setting ``delay_setup`` to ``True`` 
    8085    before defining your entities. 
     
    95100    create_all() 
    96101 
     102 
    97103def cleanup_all(): 
    98104    '''Drop table and clear mapper for all entities, and clear all metadatas.