Changeset 475 for elixir/trunk/elixir/relationships.py
- Timestamp:
- 09/29/09 14:14:37 (3 years ago)
- Files:
-
- 1 modified
-
elixir/trunk/elixir/relationships.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/elixir/relationships.py
r465 r475 870 870 if options.MIGRATION_TO_07_AID: 871 871 self.column_format = \ 872 migration_aid_m2m_column_formatter(self.column_format) 872 migration_aid_m2m_column_formatter( 873 lambda data: options.OLD_M2MCOL_NAMEFORMAT % data, 874 self.column_format) 873 875 874 876 self.filter = filter … … 995 997 996 998 joins = (self.primaryjoin_clauses, self.secondaryjoin_clauses) 997 for num, desc, fk_name, rel, colnames in (998 (0, e1_desc, source_fk_name, self, self. local_colname),999 (1, e2_desc, target_fk_name, self.inverse, self .remote_colname)):999 for num, desc, fk_name, rel, inverse, colnames in ( 1000 (0, e1_desc, source_fk_name, self, self.inverse, self.local_colname), 1001 (1, e2_desc, target_fk_name, self.inverse, self, self.remote_colname)): 1000 1002 1001 1003 fk_colnames = [] … … 1005 1007 assert len(colnames) == len(desc.primary_keys) 1006 1008 else: 1007 #FIXME: desc is not the target desc. Do I need to fix to 1008 # code or the doc? in fact the relname corresponds to the 1009 # relationship going from the entity to the M2M, so the new 1010 # naming scheme might not really make sense 1011 data = {# relationship info 1009 # The data generated here will be fed to the M2M column 1010 # formatter to generate the name of the columns of the 1011 # intermediate table for *one* side of the relationship, 1012 # that is, from the intermediate table to the current 1013 # entity, as stored in the "desc" variable. 1014 data = {# A) relationships info 1015 1016 # the name of the rel going *from* the entity 1017 # we are currently generating a column pointing 1018 # *to*. This is generally *not* what you want to 1019 # use. eg in a "Post" and "Tag" example, with 1020 # relationships named 'tags' and 'posts', when 1021 # creating the columns from the intermediate 1022 # table to the "Post" entity, 'relname' will 1023 # contain 'tags'. 1012 1024 'relname': rel and rel.name or 'inverse', 1025 1026 # the name of the inverse relationship. In the 1027 # above example, 'inversename' will contain 1028 # 'posts'. 1029 'inversename': inverse and inverse.name 1030 or 'inverse', 1031 # is A == B? 1013 1032 'selfref': e1_desc is e2_desc, 1033 # provided for backward compatibility, DO NOT USE! 1014 1034 'num': num, 1035 # provided for backward compatibility, DO NOT USE! 1015 1036 'numifself': e1_desc is e2_desc and str(num + 1) 1016 1037 or '', 1017 # source (not target!) info 1018 'source': desc.entity, 1038 # B) target information (from the perspective of 1039 # the intermediate table) 1040 'target': desc.entity, 1019 1041 'entity': desc.entity.__name__.lower(), 1020 'tablename': desc.tablename 1042 'tablename': desc.tablename, 1043 1044 # C) current (intermediate) table name 1045 'current_table': tablename 1021 1046 } 1022 1047 colnames = [] … … 1045 1070 ondelete = rel and rel.ondelete 1046 1071 1072 #FIXME: fk_name is misleading 1047 1073 constraints.append( 1048 1074 ForeignKeyConstraint(fk_colnames, fk_refcols, … … 1104 1130 1105 1131 1106 def alternate_m2m_column_formatter(data): 1107 if data['selfref']: 1108 return options.NEW_M2MCOL_NAMEFORMAT % data 1109 else: 1110 return options.OLD_M2MCOL_NAMEFORMAT % data 1111 1112 1113 def migration_aid_m2m_column_formatter(formatter): 1132 def migration_aid_m2m_column_formatter(oldformatter, newformatter): 1114 1133 def debug_formatter(data): 1115 new_name =formatter(data)1116 old_name = options.OLD_M2MCOL_NAMEFORMAT % data1134 old_name = oldformatter(data) 1135 new_name = newformatter(data) 1117 1136 if new_name != old_name: 1118 1137 complete_data = data.copy() 1119 1138 complete_data.update(old_name=old_name, 1120 1139 new_name=new_name, 1121 dir=data['num'] is 0 and 'local' or 'remote')1140 targetname=data['target'].__name__) 1122 1141 # Specifying a stacklevel is useless in this case as the name 1123 1142 # generation is triggered by setup_all(), not by the declaration 1124 1143 # of the offending relationship. 1125 #FIXME: entity is probably wrong here since it refers to the target1126 #entity.1127 warnings.warn("The generated column name for the '%(relname)s' "1128 "relationship on the '%( entity)s' entity changed"1129 " from '%(old_name)s' to '%(new_name)s'."1144 warnings.warn("The '%(old_name)s' column in the " 1145 "'%(current_table)s' table, used as the " 1146 "intermediate table for the '%(relname)s' " 1147 "relationship on the '%(targetname)s' entity " 1148 "was renamed to '%(new_name)s'." 1130 1149 % complete_data) 1131 1150 return new_name
