diff --git a/ChangeLog b/ChangeLog index 6ad1a4429f95718bf4314a2cafeec3dfb380ffe5_Q2hhbmdlTG9n..029ef5e02a9b4a09c9d97a8ca2261a1d3a59d553_Q2hhbmdlTG9n 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ -- * consider subqueries in variables graph * py datetime support (must be explicitly activated until we drop mx.DateTime support) - + * implements main_relation on ColumnAlias 2009-02-17 -- 0.21.0 * new type solver based on gecode diff --git a/nodes.py b/nodes.py index 6ad1a4429f95718bf4314a2cafeec3dfb380ffe5_bm9kZXMucHk=..029ef5e02a9b4a09c9d97a8ca2261a1d3a59d553_bm9kZXMucHk= 100644 --- a/nodes.py +++ b/nodes.py @@ -899,6 +899,20 @@ return None return iter(self.stinfo['selected']).next() + def main_relation(self): + """Return the relation where this variable is used in the rhs. + + It is useful for cases where this variable is final and we are + looking for the entity to which it belongs. + """ + for ref in self.references(): + rel = ref.relation() + if rel is None: + continue + if rel.r_type != 'is' and self.name != rel.children[0].name: + return rel + return None + class ColumnAlias(Referenceable): __slots__ = ('colnum', 'query', @@ -1005,20 +1019,6 @@ stinfo = self.stinfo return len(stinfo['selected']) + len(stinfo['relations']) - def main_relation(self): - """Return the relation where this variable is used in the rhs. - - It is useful for cases where this variable is final and we are - looking for the entity to which it belongs. - """ - for ref in self.references(): - rel = ref.relation() - if rel is None: - continue - if rel.r_type != 'is' and self.name != rel.children[0].name: - return rel - return None - build_visitor_stub((SubQuery, And, Or, Not, Exists, Relation, Comparison, MathExpression, Function, Constant, diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py index 6ad1a4429f95718bf4314a2cafeec3dfb380ffe5_dGVzdC91bml0dGVzdF9ub2Rlcy5weQ==..029ef5e02a9b4a09c9d97a8ca2261a1d3a59d553_dGVzdC91bml0dGVzdF9ub2Rlcy5weQ== 100644 --- a/test/unittest_nodes.py +++ b/test/unittest_nodes.py @@ -472,7 +472,8 @@ self.assertEquals(N.get_description(), 'firstname') # XXX how to choose self.assertEquals(X.selected_index(), 0) self.assertEquals(N.selected_index(), None) - + self.assertEquals(X.main_relation(), None) + # non regression tests #################################################### def test_get_description_and_get_type(self):