Changeset 477

Show
Ignore:
Timestamp:
09/29/09 18:12:03 (5 years ago)
Author:
ged
Message:

- Added a "table_kwargs" argument on ManyToMany relationships to pass any

extra keyword arguments to the underlying Table object (handles half of
ticket #94).

Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r469 r477  
    1818- Added (or rather fixed and documented) a "table" argument on ManyToMany 
    1919  relationships to allow using a manually-defined Table (closes #44). 
    20 - Added a "schema" argument on ManyToMany relationship to be able to create the 
    21   ManyToMany table in a custom schema and not necessarily the same schema as 
    22   the table of the "source" entity (patch from Diez B. Roggisch). 
     20- Added a "schema" argument on ManyToMany relationships to be able to create  
     21  the ManyToMany table in a custom schema and not necessarily the same schema  
     22  as the table of the "source" entity (patch from Diez B. Roggisch). 
     23- Added a "table_kwargs" argument on ManyToMany relationships to pass any 
     24  extra keyword arguments to the underlying Table object (ticket #94). 
    2325- Added a new "target_column" argument on ManyToOne relationships so that you 
    2426  can target unique but non-primary key columns. At the moment, this only works 
  • elixir/trunk/elixir/relationships.py

    r476 r477  
    301301|                    | ``set null``, or ``set default``.                      | 
    302302+--------------------+--------------------------------------------------------+ 
    303 | ``column_format``  | DEPRECATED. Specify an alternate format string for     | 
     303| ``table_kwargs``   | A dictionary holding any other keyword argument you    | 
     304|                    | might want to pass to the underlying Table object.     | 
     305+--------------------+--------------------------------------------------------+| ``column_format``  | DEPRECATED. Specify an alternate format string for     | 
    304306|                    | naming the                                             | 
    305307|                    | columns in the mapping table.  The default value is    | 
     
    839841                 column_format=None, 
    840842                 filter=None, 
     843                 table_kwargs=None, 
    841844                 *args, **kwargs): 
    842845        self.user_tablename = tablename 
     
    880883            if 'viewonly' not in kwargs: 
    881884                kwargs['viewonly'] = True 
     885 
     886        self.table_kwargs = table_kwargs or {} 
    882887 
    883888        self.primaryjoin_clauses = [] 
     
    976981                       self.target.__name__)) 
    977982 
    978             self.table = Table(tablename, e1_desc.metadata, autoload=True) 
     983            self.table = Table(tablename, e1_desc.metadata, autoload=True, 
     984                               **self.table_kwargs) 
    979985            if 'primaryjoin' not in self.kwargs or \ 
    980986               'secondaryjoin' not in self.kwargs: 
     
    10801086 
    10811087            self.table = Table(tablename, e1_desc.metadata, 
    1082                                schema=schema, *args) 
     1088                               schema=schema, *args, **self.table_kwargs) 
    10831089            if DEBUG: 
    10841090                print self.table.repr2() 
  • elixir/trunk/tests/test_m2m.py

    r475 r477  
    5555        assert a in b.as_ 
    5656        assert b in a.bs_ 
     57 
     58    def test_table_kwargs(self): 
     59        class A(Entity): 
     60            using_options(shortnames=True) 
     61            name = Field(String(60)) 
     62            bs_ = ManyToMany('B', table_kwargs={'info': {'test': True}}) 
     63 
     64        class B(Entity): 
     65            using_options(shortnames=True) 
     66            name = Field(String(60)) 
     67            as_ = ManyToMany('A') 
     68 
     69        setup_all(True) 
     70        A.mapper.compile() 
     71 
     72        assert A.bs_.property.secondary.info['test'] is True 
    5773 
    5874    def test_custom_global_column_nameformat(self):