1107 Fix prefetch when a ForeignKey has db_column_name set#1111
1107 Fix prefetch when a ForeignKey has db_column_name set#1111dantownsend wants to merge 12 commits intomasterfrom
prefetch when a ForeignKey has db_column_name set#1111Conversation
This reverts commit 2de72c7.
…en-fk-has-db-column-name
|
@dantownsend Hi. Will it ever reach release? Without this fix, it's hard to switch from Django ORM. |
Yes, will merge it in once the tests are passing. |
Thanks. I'm sorry for writing the same message twice - I'm a bit of a dumbass:) Have you considered taking the |
|
@dantownsend Just one question. Shouldn't this be much simpler without the # your modified code without match_db_column_name param
column_object = next(
(
i
for i in self.columns
if (i._meta.name == column_name)
or (i._meta.db_column_name == column_name)
),
None,
)
if column_object is None:
raise ValueError(f"No matching column found with name == {name}")and test like this: # in tests/columns/test_db_column_name.py
def test_prefetch(self):
"""
Make sure that foreign keys with a ``db_column_name`` work
with prefetch objects.
https://github.com/piccolo-orm/piccolo/issues/1107
"""
manager = Manager.objects().create(name="Guido").run_sync()
self.insert_band(manager=manager)
band = (
Band.objects(Band.manager)
.where(Band.manager == manager.id)
.first()
.run_sync()
)
self.assertEqual(
band.to_dict(),
{
"id": band.id,
"name": "Pythonistas",
"popularity": 1000,
"manager": {"id": manager.id, "name": "Guido"},
},
)Sorry if I'm wrong and don't understand this correctly but this is just suggestion. |
Yeah, I need a table with a FK with |
Resolves #1107