Changeset 426
- Timestamp:
- 12/05/08 15:02:36 (5 years ago)
- Location:
- elixir/trunk
- Files:
-
- 2 modified
-
CHANGES (modified) (1 diff)
-
elixir/relationships.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/CHANGES
r425 r426 75 75 - Added workaround for an odd mod_python behavior (class.__module__ returns a 76 76 weird name which is not in sys.modules). 77 - Fixed filter argument on OneToMany relationship leaking the filter to the 78 unfiltered relationship. 77 79 78 80 0.6.1 - 2008-08-18 -
elixir/trunk/elixir/relationships.py
r421 r426 455 455 456 456 # transform callable arguments 457 for arg in ('primaryjoin', 'secondaryjoin', 'remote_side', 'filter',457 for arg in ('primaryjoin', 'secondaryjoin', 'remote_side', 458 458 'foreign_keys'): 459 459 kwarg = kwargs.get(arg, None) … … 749 749 self.filter = filter 750 750 if filter is not None: 751 # We set viewonly to True by default for filtered relationship ,751 # We set viewonly to True by default for filtered relationships, 752 752 # unless manually overridden. 753 753 # This is not strictly necessary, as SQLAlchemy allows non viewonly … … 793 793 kwargs['remote_side'] = self.inverse.foreign_key 794 794 795 # Contrary to ManyToMany relationships, we need to specify the join 796 # clauses even if this relationship is not self-referencial because 797 # there could be several ManyToOne from the target class to us. 795 798 joinclauses = self.inverse.primaryjoin_clauses 796 799 if self.filter: 797 joinclauses.append(self.filter(self.target.table.c)) 800 # We need to make a copy of the joinclauses, to not add the filter 801 # on the backref 802 joinclauses = joinclauses[:] + [self.filter(self.target.table.c)] 798 803 if joinclauses: 799 804 kwargs['primaryjoin'] = and_(*joinclauses) … … 816 821 table=None, schema=None, 817 822 column_format=None, 823 filter=None, 818 824 *args, **kwargs): 819 825 self.user_tablename = tablename … … 829 835 self.onupdate = onupdate 830 836 831 self. secondary_table = table837 self.table = table 832 838 self.schema = schema 833 839 … … 841 847 self.column_format = column_format or options.M2MCOL_NAMEFORMAT 842 848 849 self.filter = filter 850 if filter is not None: 851 # We set viewonly to True by default for filtered relationships, 852 # unless manually overridden. 853 if 'viewonly' not in kwargs: 854 kwargs['viewonly'] = True 855 843 856 self.primaryjoin_clauses = [] 844 857 self.secondaryjoin_clauses = [] … … 846 859 super(ManyToMany, self).__init__(of_kind, *args, **kwargs) 847 860 861 def get_table(self): 862 warnings.warn("The secondary_table attribute on ManyToMany objects is" 863 "deprecated", DeprecationWarning, stacklevel=2) 864 return self.table 865 secondary_table = property(get_table) 866 848 867 def match_type_of(self, other): 849 868 return isinstance(other, ManyToMany) 850 869 851 870 def create_tables(self): 852 if self. secondary_table:871 if self.table: 853 872 if 'primaryjoin' not in self.kwargs or \ 854 873 'secondaryjoin' not in self.kwargs: … … 857 876 858 877 if self.inverse: 859 if self.inverse. secondary_table:860 self. secondary_table = self.inverse.secondary_table878 if self.inverse.table: 879 self.table = self.inverse.table 861 880 self.primaryjoin_clauses = self.inverse.secondaryjoin_clauses 862 881 self.secondaryjoin_clauses = self.inverse.primaryjoin_clauses … … 927 946 self.target.__name__)) 928 947 929 self.secondary_table = Table(tablename, e1_desc.metadata, 930 autoload=True) 948 self.table = Table(tablename, e1_desc.metadata, autoload=True) 931 949 if 'primaryjoin' not in self.kwargs or \ 932 950 'secondaryjoin' not in self.kwargs: … … 998 1016 args = columns + constraints 999 1017 1000 self. secondary_table = Table(tablename, e1_desc.metadata,1001 schema=schema, *args)1018 self.table = Table(tablename, e1_desc.metadata, 1019 schema=schema, *args) 1002 1020 if DEBUG: 1003 print self. secondary_table.repr2()1021 print self.table.repr2() 1004 1022 1005 1023 def _build_join_clauses(self): … … 1021 1039 1022 1040 self.primaryjoin_clauses, self.secondaryjoin_clauses = \ 1023 _get_join_clauses(self. secondary_table,1041 _get_join_clauses(self.table, 1024 1042 self.local_colname, self.remote_colname, 1025 1043 self.entity.table) 1026 1044 1027 1045 def get_prop_kwargs(self): 1028 kwargs = {'secondary': self. secondary_table,1046 kwargs = {'secondary': self.table, 1029 1047 'uselist': self.uselist} 1030 1048 1031 if self.target is self.entity: 1049 if self.filter: 1050 # we need to make a copy of the joinclauses 1051 secondaryjoin_clauses = self.secondaryjoin_clauses[:] + \ 1052 [self.filter(self.target.table.c)] 1053 else: 1054 secondaryjoin_clauses = self.secondaryjoin_clauses 1055 1056 if self.target is self.entity or self.filter: 1032 1057 kwargs['primaryjoin'] = and_(*self.primaryjoin_clauses) 1033 kwargs['secondaryjoin'] = and_(*se lf.secondaryjoin_clauses)1058 kwargs['secondaryjoin'] = and_(*secondaryjoin_clauses) 1034 1059 1035 1060 kwargs.update(self.kwargs)
