Skip to content

Commit 00fb796

Browse files
committed
Codegen: ignore synth properties in dbschemegen
1 parent d2c9847 commit 00fb796

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

misc/codegen/generators/dbschemegen.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def cls_to_dbscheme(cls: schema.Class, lookup: typing.Dict[str, schema.Class], a
4949
# Leaf classes need a table to bind the `@` ids
5050
# 1-to-1 properties are added to a class specific table
5151
# in other cases, separate tables are used for the properties, and a class specific table is unneeded
52-
if not cls.derived or any(f.is_single for f in cls.properties):
52+
if not cls.derived or any(f.is_single and not f.synth for f in cls.properties):
5353
binding = not cls.derived
5454
keyset = KeySet(["id"]) if cls.derived else None
5555
yield Table(
@@ -58,12 +58,15 @@ def cls_to_dbscheme(cls: schema.Class, lookup: typing.Dict[str, schema.Class], a
5858
columns=[
5959
Column("id", type=dbtype(cls.name), binding=binding),
6060
] + [
61-
Column(f.name, dbtype(f.type, add_or_none_except)) for f in cls.properties if f.is_single
61+
Column(f.name, dbtype(f.type, add_or_none_except))
62+
for f in cls.properties if f.is_single and not f.synth
6263
],
6364
dir=dir,
6465
)
6566
# use property-specific tables for 1-to-many and 1-to-at-most-1 properties
6667
for f in cls.properties:
68+
if f.synth:
69+
continue
6770
if f.is_unordered:
6871
yield Table(
6972
name=inflection.tableize(f"{cls.name}_{f.name}"),

misc/codegen/test/test_dbschemegen.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,32 @@ def test_ipa_derived_classes_ignored(generate):
566566
)
567567

568568

569+
def test_synth_properties_ignored(generate):
570+
assert generate([
571+
schema.Class(name="A", properties=[
572+
schema.SingleProperty("x", "a"),
573+
schema.SingleProperty("y", "b", synth=True),
574+
schema.SingleProperty("z", "c"),
575+
schema.OptionalProperty("foo", "bar", synth=True),
576+
schema.RepeatedProperty("baz", "bazz", synth=True),
577+
schema.RepeatedOptionalProperty("bazzz", "bazzzz", synth=True),
578+
schema.RepeatedUnorderedProperty("bazzzzz", "bazzzzzz", synth=True),
579+
]),
580+
]) == dbscheme.Scheme(
581+
src=schema_file.name,
582+
includes=[],
583+
declarations=[
584+
dbscheme.Table(
585+
name="as",
586+
columns=[
587+
dbscheme.Column("id", "@a", binding=True),
588+
dbscheme.Column("x", "a"),
589+
dbscheme.Column("z", "c"),
590+
],
591+
)
592+
],
593+
)
594+
595+
569596
if __name__ == '__main__':
570597
sys.exit(pytest.main([__file__] + sys.argv[1:]))

0 commit comments

Comments
 (0)