Changeset 297
- Timestamp:
- 02/05/08 00:20:01 (5 years ago)
- Location:
- elixir/trunk
- Files:
-
- 2 modified
-
elixir/relationships.py (modified) (3 diffs)
-
tests/test_m2m.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/elixir/relationships.py
r269 r297 225 225 | | by a minus (for descending order). | 226 226 +--------------------+--------------------------------------------------------+ 227 | ``column_format`` | Specify an alternate format string for naming the | 228 | | columns in the mapping table. The default value is | 229 | | defined in ``elixir.options.M2MCOL_NAMEFORMAT``. You | 230 | | will be passed ``tablename``, ``key``, and ``entity`` | 231 | | as arguments to the format string. | 232 +--------------------+--------------------------------------------------------+ 233 227 234 228 235 ================ … … 671 678 self.ondelete = kwargs.pop('ondelete', None) 672 679 self.onupdate = kwargs.pop('onupdate', None) 680 self.column_format = kwargs.pop('column_format', options.M2MCOL_NAMEFORMAT) 673 681 674 682 self.secondary_table = None … … 749 757 750 758 for pk_col in desc.primary_keys: 751 colname = options.M2MCOL_NAMEFORMAT% \759 colname = self.column_format % \ 752 760 {'tablename': desc.tablename, 753 'key': pk_col.key} 754 761 'key': pk_col.key, 762 'entity': desc.entity.__name__.lower()} 763 755 764 # In case we have a many-to-many self-reference, we 756 765 # need to tweak the names of the columns so that we -
elixir/trunk/tests/test_m2m.py
r271 r297 13 13 def teardown(self): 14 14 cleanup_all(True) 15 15 16 16 def test_simple(self): 17 17 class A(Entity): … … 35 35 assert a in b.as_ 36 36 assert b in a.bs_ 37 38 def test_column_format(self): 39 class A(Entity): 40 using_options(tablename='aye') 41 name = Field(String(60)) 42 bs_ = ManyToMany('B', column_format='%(entity)s_%(key)s') 37 43 44 class B(Entity): 45 using_options(tablename='bee') 46 name = Field(String(60)) 47 as_ = ManyToMany('A', column_format='%(entity)s_%(key)s') 48 49 setup_all(True) 50 51 b1 = B(name='b1', as_=[A(name='a1')]) 52 53 session.flush() 54 session.clear() 55 56 a = A.query.one() 57 b = B.query.one() 58 59 assert a in b.as_ 60 assert b in a.bs_ 61 62 found_a = False 63 found_b = False 64 for column in A.mapper.get_property('bs_').secondary.columns: 65 if column.name == 'a_id': found_a = True 66 elif column.name == 'b_id': found_b = True 67 assert found_a 68 assert found_b 69 38 70 def test_multi_pk_in_target(self): 39 71 class A(Entity):
