Exemplo n.º 1
0
 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)
    def _unhashable_fixture(self, metadata, load_on_pending=False):
        class MyHashType(sa.TypeDecorator):
            impl = sa.String(100)

            def process_bind_param(self, value, dialect):
                return ";".join(
                    "%s=%s" % (k, v)
                    for k, v in sorted(value.items(), key=lambda key: key[0]))

            def process_result_value(self, value, dialect):
                return dict(elem.split("=", 1) for elem in value.split(";"))

        category = Table(
            "category",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", MyHashType()),
        )
        article = Table(
            "article",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", MyHashType()),
        )

        class Category(fixtures.ComparableEntity):
            pass

        class Article(fixtures.ComparableEntity):
            pass

        mapper(Category, category)
        mapper(
            Article,
            article,
            properties={
                "category":
                relationship(
                    Category,
                    primaryjoin=orm.foreign(article.c.data) == category.c.data,
                    load_on_pending=load_on_pending,
                )
            },
        )

        metadata.create_all()
        sess = Session(autoflush=False)
        data = {"im": "unhashable"}
        a1 = Article(id=1, data=data)
        c1 = Category(id=1, data=data)
        if load_on_pending:
            sess.add(c1)
        else:
            sess.add_all([c1, a1])
        sess.flush()
        if load_on_pending:
            sess.add(a1)
        return Category, Article, sess, a1, c1
Exemplo n.º 3
0
 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("%"))),
     )
    def setup_mappers(cls):
        mapper(
            cls.classes.Person,
            cls.tables.person,
            properties=dict(pets=relationship(
                cls.classes.Pet,
                primaryjoin=(
                    orm.foreign(cls.tables.pets.c.person_id) == sa.cast(
                        sa.type_coerce(cls.tables.person.c.id, Integer),
                        Integer,
                    )),
            )),
        )

        mapper(cls.classes.Pet, cls.tables.pets)
Exemplo n.º 5
0
    def _join_fixture_remote_local_multiple_ref(self, **kw):
        def fn(a, b):
            return (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)),
            ),
        )