def setup_mappers(cls):
        a, b = cls.tables.a, cls.tables.b

        class A(cls.Comparable):
            pass

        class B(cls.Comparable):
            pass

        class C(cls.Comparable):
            def __init__(self, b1, b2):
                self.b1, self.b2 = b1, b2

            def __composite_values__(self):
                return self.b1, self.b2

            def __eq__(self, other):
                return (isinstance(other, C) and other.b1 == self.b1
                        and other.b2 == self.b2)

        mapper(
            A,
            a,
            properties={
                "b2": relationship(B),
                "c": composite(C, "b1", "b2")
            },
        )
        mapper(B, b)
Exemple #2
0
    def setup_mappers(cls):
        foo = cls.tables.foo

        Point = cls._type_fixture()

        mapper(Foo,
               foo,
               properties={"data": composite(Point, foo.c.x, foo.c.y)})
    def setup_mappers(cls):
        values, descriptions = cls.tables.values, cls.tables.descriptions

        class Descriptions(cls.Comparable):
            pass

        class Values(cls.Comparable):
            pass

        class CustomValues(cls.Comparable, list):
            def __init__(self, *args):
                self.extend(args)

            def __composite_values__(self):
                return self

        desc_values = select(
            [values, descriptions.c.d1, descriptions.c.d2],
            descriptions.c.id == values.c.description_id,
        ).alias("descriptions_values")

        mapper(
            Descriptions,
            descriptions,
            properties={
                "values":
                relationship(Values, lazy="dynamic"),
                "custom_descriptions":
                composite(CustomValues, descriptions.c.d1, descriptions.c.d2),
            },
        )

        mapper(
            Values,
            desc_values,
            properties={
                "custom_values":
                composite(CustomValues, desc_values.c.v1, desc_values.c.v2)
            },
        )
    def _fixture(self):
        class AB(object):
            def __init__(self, a, b, cd):
                self.a = a
                self.b = b
                self.cd = cd

            @classmethod
            def generate(cls, a, b, c, d):
                return AB(a, b, CD(c, d))

            def __composite_values__(self):
                return (self.a, self.b) + self.cd.__composite_values__()

            def __eq__(self, other):
                return (isinstance(other, AB) and self.a == other.a
                        and self.b == other.b and self.cd == other.cd)

            def __ne__(self, other):
                return not self.__eq__(other)

        class CD(object):
            def __init__(self, c, d):
                self.c = c
                self.d = d

            def __composite_values__(self):
                return (self.c, self.d)

            def __eq__(self, other):
                return (isinstance(other, CD) and self.c == other.c
                        and self.d == other.d)

            def __ne__(self, other):
                return not self.__eq__(other)

        class Thing(object):
            def __init__(self, ab):
                self.ab = ab

        stuff = self.tables.stuff
        mapper(
            Thing,
            stuff,
            properties={
                "ab":
                composite(AB.generate, stuff.c.a, stuff.c.b, stuff.c.c,
                          stuff.c.d)
            },
        )
        return Thing, AB, CD
Exemple #5
0
    def setup_mappers(cls):
        foo = cls.tables.foo

        Point = cls._type_fixture()

        # in this case, this is not actually a MutableComposite.
        # so we don't expect it to track changes
        mapper(
            Foo,
            foo,
            properties={
                "data": composite(lambda x, y: Point(x, y), foo.c.x, foo.c.y)
            },
        )