sqlalchemy.orm.relationships.JoinCondition

Here are the examples of the python api sqlalchemy.orm.relationships.JoinCondition taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

33 Examples 7

Example 1

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2m(self, **kw):
        return relationships.JoinCondition(
                    self.m2mleft,
                    self.m2mright,
                    self.m2mleft,
                    self.m2mright,
                    secondary=self.m2msecondary,
                    **kw
                )

Example 2

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2m_backref(self, **kw):
        """return JoinCondition in the same way RelationshipProperty
        calls it for a backref on an m2m.

        """
        j1 = self._join_fixture_m2m()
        return j1, relationships.JoinCondition(
                    self.m2mright,
                    self.m2mleft,
                    self.m2mright,
                    self.m2mleft,
                    secondary=self.m2msecondary,
                    primaryjoin=j1.secondaryjoin_minus_local,
                    secondaryjoin=j1.primaryjoin_minus_local
                )

Example 3

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m(self, **kw):
        return relationships.JoinCondition(
                    self.left,
                    self.right,
                    self.left,
                    self.right,
                    **kw
                )

Example 4

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o(self, **kw):
        return relationships.JoinCondition(
                    self.right,
                    self.left,
                    self.right,
                    self.left,
                    **kw
                )

Example 5

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_selfref(self, **kw):
        return relationships.JoinCondition(
            self.selfref,
            self.selfref,
            self.selfref,
            self.selfref,
            **kw
        )

Example 6

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o_selfref(self, **kw):
        return relationships.JoinCondition(
            self.selfref,
            self.selfref,
            self.selfref,
            self.selfref,
            remote_side=set([self.selfref.c.id]),
            **kw
        )

Example 7

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_composite_selfref(self, **kw):
        return relationships.JoinCondition(
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            **kw
        )

Example 8

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o_composite_selfref(self, **kw):
        return relationships.JoinCondition(
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            remote_side=set([self.composite_selfref.c.id,
                            self.composite_selfref.c.group_id]),
            **kw
        )

Example 9

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_composite_selfref_func(self, **kw):
        return relationships.JoinCondition(
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            primaryjoin=and_(
                self.composite_selfref.c.group_id ==
                    func.foo(self.composite_selfref.c.group_id),
                self.composite_selfref.c.parent_id ==
                    self.composite_selfref.c.id
            ),
            **kw
        )

Example 10

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_composite_selfref_func_remote_side(self, **kw):
        return relationships.JoinCondition(
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            primaryjoin=and_(
                self.composite_selfref.c.group_id ==
                    func.foo(self.composite_selfref.c.group_id),
                self.composite_selfref.c.parent_id ==
                    self.composite_selfref.c.id
            ),
            remote_side=set([self.composite_selfref.c.parent_id]),
            **kw
        )

Example 11

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_composite_selfref_func_annotated(self, **kw):
        return relationships.JoinCondition(
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            self.composite_selfref,
            primaryjoin=and_(
                remote(self.composite_selfref.c.group_id) ==
                    func.foo(self.composite_selfref.c.group_id),
                remote(self.composite_selfref.c.parent_id) ==
                    self.composite_selfref.c.id
            ),
            **kw
        )

Example 12

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_compound_expression_1_non_annotated(self, **kw):
        return relationships.JoinCondition(
            self.left,
            self.right,
            self.left,
            self.right,
            primaryjoin=(self.left.c.x + self.left.c.y) == \
                            (
                                self.right.c.x * self.right.c.y
                            ),
            **kw
        )

Example 13

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_base_to_joined_sub(self, **kw):
        # see test/orm/inheritance/test_abc_inheritance:TestaTobM2O
        # and others there
        right = self.base_w_sub_rel.join(self.rel_sub,
            self.base_w_sub_rel.c.id == self.rel_sub.c.id
        )
        return relationships.JoinCondition(
            self.base_w_sub_rel,
            right,
            self.base_w_sub_rel,
            self.rel_sub,
            primaryjoin=self.base_w_sub_rel.c.sub_id == \
                        self.rel_sub.c.id,
            **kw
        )

Example 14

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_joined_sub_to_base(self, **kw):
        left = self.base.join(self.sub_w_base_rel,
                        self.base.c.id == self.sub_w_base_rel.c.id)
        return relationships.JoinCondition(
            left,
            self.base,
            self.sub_w_base_rel,
            self.base,
            primaryjoin=self.sub_w_base_rel.c.base_id == self.base.c.id
        )

Example 15

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o_joined_sub_to_sub_on_base(self, **kw):
        # this is a late add - a variant of the test case
        # in #2491 where we join on the base cols instead.  only
        # m2o has a problem at the time of this test.
        left = self.base.join(self.sub, self.base.c.id == self.sub.c.id)
        right = self.base.join(self.sub_w_base_rel,
                        self.base.c.id == self.sub_w_base_rel.c.id)
        return relationships.JoinCondition(
            left,
            right,
            self.sub,
            self.sub_w_base_rel,
            primaryjoin=self.sub_w_base_rel.c.base_id == self.base.c.id,
        )

Example 16

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_joined_sub_to_sub(self, **kw):
        left = self.base.join(self.sub, self.base.c.id == self.sub.c.id)
        right = self.base.join(self.sub_w_sub_rel,
                        self.base.c.id == self.sub_w_sub_rel.c.id)
        return relationships.JoinCondition(
            left,
            right,
            self.sub,
            self.sub_w_sub_rel,
            primaryjoin=self.sub.c.id == self.sub_w_sub_rel.c.sub_id
        )

Example 17

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o_sub_to_joined_sub(self, **kw):
        # see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate,
        right = self.base.join(self.right_w_base_rel,
                        self.base.c.id == self.right_w_base_rel.c.id)
        return relationships.JoinCondition(
            self.right_w_base_rel,
            right,
            self.right_w_base_rel,
            self.right_w_base_rel,
        )

Example 18

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_m2o_sub_to_joined_sub_func(self, **kw):
        # see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate,
        right = self.base.join(self.right_w_base_rel,
                        self.base.c.id == self.right_w_base_rel.c.id)
        return relationships.JoinCondition(
            self.right_w_base_rel,
            right,
            self.right_w_base_rel,
            self.right_w_base_rel,
            primaryjoin=self.right_w_base_rel.c.base_id == \
                func.foo(self.base.c.id)
        )

Example 19

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2o_joined_sub_to_base(self, **kw):
        left = self.base.join(self.sub,
                        self.base.c.id == self.sub.c.id)

        # see test_relationships->AmbiguousJoinInterpretedAsSelfRef
        return relationships.JoinCondition(
            left,
            self.sub,
            left,
            self.sub,
        )

Example 20

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_to_annotated_func(self, **kw):
        return relationships.JoinCondition(
                    self.left,
                    self.right,
                    self.left,
                    self.right,
                    primaryjoin=self.left.c.id ==
                        foreign(func.foo(self.right.c.lid)),
                    **kw
                )

Example 21

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_to_oldstyle_func(self, **kw):
        return relationships.JoinCondition(
                    self.left,
                    self.right,
                    self.left,
                    self.right,
                    primaryjoin=self.left.c.id ==
                        func.foo(self.right.c.lid),
                    consider_as_foreign_keys=[self.right.c.lid],
                    **kw
                )

Example 22

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_o2m_o_side_none(self, **kw):
        return relationships.JoinCondition(
                    self.left,
                    self.right,
                    self.left,
                    self.right,
                    primaryjoin=and_(self.left.c.id == self.right.c.lid,
                                        self.left.c.x == 5),
                    **kw
                    )

Example 23

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_purely_single_o2m(self, **kw):
        return relationships.JoinCondition(
                    self.purely_single_col,
                    self.purely_single_col,
                    self.purely_single_col,
                    self.purely_single_col,
                    support_sync=False,
                    primaryjoin=
                        self.purely_single_col.c.path.like(
                            remote(
                                foreign(
                                    self.purely_single_col.c.path.concat('%')
                                )
                            )
                        )
                )

Example 24

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_purely_single_m2o(self, **kw):
        return relationships.JoinCondition(
                    self.purely_single_col,
                    self.purely_single_col,
                    self.purely_single_col,
                    self.purely_single_col,
                    support_sync=False,
                    primaryjoin=
                        remote(self.purely_single_col.c.path).like(
                            foreign(self.purely_single_col.c.path.concat('%'))
                        )
                )

Example 25

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_remote_local_multiple_ref(self, **kw):
        fn = lambda a, b: ((a == b) | (b == a))
        return relationships.JoinCondition(
            self.selfref, self.selfref,
            self.selfref, self.selfref,
            support_sync=False,
            primaryjoin=fn(
                # we're putting a do-nothing annotation on
                # "a" so that the left/right is preserved;
                # annotation vs. non seems to affect __eq__ behavior
                self.selfref.c.sid._annotate({"foo": "bar"}),
                foreign(remote(self.selfref.c.sid)))
        )

Example 26

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def test_determine_join_ambiguous_fks_o2m(self):
        assert_raises_message(
            exc.AmbiguousForeignKeysError,
            "Could not determine join condition between "
            "parent/child tables on relationship None - "
            "there are multiple foreign key paths linking "
            "the tables.  Specify the 'foreign_keys' argument, "
            "providing a list of those columns which "
            "should be counted as containing a foreign "
            "key reference to the parent table.",
            relationships.JoinCondition,
                    self.left,
                    self.right_multi_fk,
                    self.left,
                    self.right_multi_fk,
        )

Example 27

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def test_determine_join_no_fks_o2m(self):
        self._assert_raises_no_join(
            relationships.JoinCondition,
            "None", None,
                    self.left,
                    self.selfref,
                    self.left,
                    self.selfref,
        )

Example 28

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def test_determine_join_ambiguous_fks_m2m(self):

        self._assert_raises_ambig_join(
            relationships.JoinCondition,
            "None", self.m2msecondary_ambig_fks,
            self.m2mleft,
            self.m2mright,
            self.m2mleft,
            self.m2mright,
            secondary=self.m2msecondary_ambig_fks
        )

Example 29

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def test_determine_join_no_fks_m2m(self):
        self._assert_raises_no_join(
            relationships.JoinCondition,
            "None", self.m2msecondary_no_fks,
                    self.m2mleft,
                    self.m2mright,
                    self.m2mleft,
                    self.m2mright,
                    secondary=self.m2msecondary_no_fks
        )

Example 30

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_fks_ambig_m2m(self):
        return relationships.JoinCondition(
                    self.m2mleft,
                    self.m2mright,
                    self.m2mleft,
                    self.m2mright,
                    secondary=self.m2msecondary_ambig_fks,
                    consider_as_foreign_keys=[
                        self.m2msecondary_ambig_fks.c.lid1,
                        self.m2msecondary_ambig_fks.c.rid1]
        )

Example 31

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_overlapping_three_tables(self, **kw):
        def _can_sync(*cols):
            for c in cols:
                if self.three_tab_c.c.contains_column(c):
                    return False
            else:
                return True
        return relationships.JoinCondition(
            self.three_tab_a,
            self.three_tab_b,
            self.three_tab_a,
            self.three_tab_b,
            support_sync=False,
            can_be_synced_fn=_can_sync,
            primaryjoin=and_(
                self.three_tab_a.c.id == self.three_tab_b.c.aid,
                self.three_tab_c.c.bid == self.three_tab_b.c.id,
                self.three_tab_c.c.aid == self.three_tab_a.c.id
            )
        )

Example 32

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_overlapping_composite_fks(self, **kw):
        return relationships.JoinCondition(
                    self.composite_target,
                    self.composite_multi_ref,
                    self.composite_target,
                    self.composite_multi_ref,
                    consider_as_foreign_keys=[self.composite_multi_ref.c.uid2,
                                    self.composite_multi_ref.c.oid],
                    **kw
                )


        cls.left = Table('lft', m,
            Column('id', Integer, primary_key=True),
            Column('x', Integer),
            Column('y', Integer),
        )
        cls.right = Table('rgt', m,
            Column('id', Integer, primary_key=True),
            Column('lid', Integer, ForeignKey('lft.id')),
            Column('x', Integer),
            Column('y', Integer),
        )

Example 33

Project: sqlalchemy
Source File: test_rel_fn.py
View license
    def _join_fixture_inh_selfref_w_entity(self, **kw):
        fake_logger = mock.Mock(info=lambda *arg, **kw: None)
        prop = mock.Mock(
            parent=mock.Mock(),
            mapper=mock.Mock(),
            logger=fake_logger
        )
        local_selectable = self.base.join(self.sub)
        remote_selectable = self.base.join(self.sub_w_sub_rel)

        sub_w_sub_rel__sub_id = self.sub_w_sub_rel.c.sub_id._annotate(
            {'parentmapper': prop.mapper})
        sub__id = self.sub.c.id._annotate({'parentmapper': prop.parent})
        sub_w_sub_rel__flag = self.base.c.flag._annotate(
            {"parentmapper": prop.mapper})
        return relationships.JoinCondition(
            local_selectable, remote_selectable,
            local_selectable, remote_selectable,
            primaryjoin=and_(
                sub_w_sub_rel__sub_id == sub__id,
                sub_w_sub_rel__flag == True
            ),
            prop=prop
        )