(self)
| 1045 | class ScalarTest(fixtures.MappedTest): |
| 1046 | @testing.provide_metadata |
| 1047 | def test_scalar_proxy(self): |
| 1048 | metadata = self.metadata |
| 1049 | |
| 1050 | parents_table = Table( |
| 1051 | class="st">"Parent", |
| 1052 | metadata, |
| 1053 | Column( |
| 1054 | class="st">"id", Integer, primary_key=True, test_needs_autoincrement=True |
| 1055 | ), |
| 1056 | Column(class="st">"name", String(128)), |
| 1057 | ) |
| 1058 | children_table = Table( |
| 1059 | class="st">"Children", |
| 1060 | metadata, |
| 1061 | Column( |
| 1062 | class="st">"id", Integer, primary_key=True, test_needs_autoincrement=True |
| 1063 | ), |
| 1064 | Column(class="st">"parent_id", Integer, ForeignKey(class="st">"Parent.id")), |
| 1065 | Column(class="st">"foo", String(128)), |
| 1066 | Column(class="st">"bar", String(128)), |
| 1067 | Column(class="st">"baz", String(128)), |
| 1068 | ) |
| 1069 | |
| 1070 | class Parent: |
| 1071 | foo = association_proxy(class="st">"child", class="st">"foo") |
| 1072 | bar = association_proxy( |
| 1073 | class="st">"child", class="st">"bar", creator=lambda v: Child(bar=v) |
| 1074 | ) |
| 1075 | baz = association_proxy( |
| 1076 | class="st">"child", class="st">"baz", creator=lambda v: Child(baz=v) |
| 1077 | ) |
| 1078 | |
| 1079 | def __init__(self, name): |
| 1080 | self.name = name |
| 1081 | |
| 1082 | class Child: |
| 1083 | def __init__(self, **kw): |
| 1084 | for attr in kw: |
| 1085 | setattr(self, attr, kw[attr]) |
| 1086 | |
| 1087 | self.mapper_registry.map_imperatively( |
| 1088 | Parent, |
| 1089 | parents_table, |
| 1090 | properties={ |
| 1091 | class="st">"child": relationship( |
| 1092 | Child, lazy=class="st">"joined", backref=class="st">"parent", uselist=False |
| 1093 | ) |
| 1094 | }, |
| 1095 | ) |
| 1096 | self.mapper_registry.map_imperatively(Child, children_table) |
| 1097 | |
| 1098 | metadata.create_all(testing.db) |
| 1099 | session = fixture_session() |
| 1100 | |
| 1101 | def roundtrip(obj): |
| 1102 | if obj not in session: |
| 1103 | session.add(obj) |
| 1104 | session.flush() |
nothing calls this directly
no test coverage detected