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

using db_column_name with ForeignKey breaks objects().select(...) when using prefetch #1107

Open
jessemcl-flwls opened this issue Oct 18, 2024 · 2 comments · May be fixed by #1111
Open

using db_column_name with ForeignKey breaks objects().select(...) when using prefetch #1107

jessemcl-flwls opened this issue Oct 18, 2024 · 2 comments · May be fixed by #1111

Comments

@jessemcl-flwls
Copy link

Thank you for addressing this issue so quickly: #1101

Sadly, this rabbit hole might go a bit deeper. With the above fix, I immediately ran into the next possibly related thing:

Again, if I have two tables with a foreign key relationship between them, and I specify the relationship using a custom db_column_name, eg:

class FooTable(Table, tablename="foo", schema="public"):
    id = Varchar(length=20, primary_key=True, null=False)
    name = Varchar(length=64, unique=True, null=False)

class BarTable(Table, tablename="bar", schema="public"):
    id = Varchar(length=20, primary_key=True, null=False)
    foo = ForeignKey(references=FooTable, null=False, db_column_name="foo_id")

Then when I try to query this relationship using prefetch:

bar = await BarTable.objects(BarTable.foo).where(BarTable.foo.id == "abc").first()

Then I get an error saying there is no matching column found.

If I leave out the prefetch, then it works without error, with the resulting dict containing the property:

  "foo": "abc"
@dantownsend
Copy link
Member

It's probably another edge case we don't have a unit test for.

Hopefully it's a fairly easy fix again - making sure we use db_column_name instead of name in the query.

@dantownsend
Copy link
Member

I've got a PR which fixes it - but needs some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants