Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: fix handling through table #392

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions pgsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,22 +464,46 @@ def _insert_op(
)
raise

# set the parent as the new entity that has changed
foreign_keys = self.query_builder._get_foreign_keys(
node.parent,
node,
)
if node in node.parent.relationship.throughs:
foreign_keys = self.query_builder._get_foreign_keys(
node.parent,
node,
)
filters[node.parent.name] = []
for payload in payloads:
primary_values: list = [
payload.data[key] for key in node.model.primary_keys
]

for i, key in enumerate(foreign_keys[node.parent.name]):
for val in primary_values:
filters[node.parent.table].append(
{foreign_keys[node.parent.name][i]: val},
)

for payload in payloads:
for i, key in enumerate(foreign_keys[node.name]):
if key == foreign_keys[node.parent.name][i]:
filters[node.parent.table].append(
{
foreign_keys[node.parent.name][
i
]: payload.data[key]
}
)
for pk in self.tree.root.model.primary_keys:
for val in primary_values:
filters[self.tree.root.table].append(
{pk: val}
)

else:
# set the parent as the new entity that has changed
foreign_keys = self.query_builder._get_foreign_keys(
node.parent,
node,
)

for payload in payloads:
for i, key in enumerate(foreign_keys[node.name]):
if key == foreign_keys[node.parent.name][i]:
filters[node.parent.table].append(
{
foreign_keys[node.parent.name][
i
]: payload.data[key]
}
)

else:

Expand Down