Join on table query without foreign key association

111 views
Skip to first unread message

苏子阔

unread,
Nov 22, 2024, 9:15:21 AM11/22/24
to Django users
In my project, I did not use foreign keys such as models ForeignKey. Instead, models were used BigIntegralField to associate with other tables
For example: customer-id=models BigIntegralField() stores the ID field of the customer table
But now what should I do if I want to use a join on query?
For example, TopUp. objects. select_delate ("customer-id").
Please help me,thank you!

Ryan Nowakowski

unread,
Nov 22, 2024, 8:40:08 PM11/22/24
to django...@googlegroups.com

Sam Brown

unread,
Nov 22, 2024, 9:03:38 PM11/22/24
to django...@googlegroups.com
Why not use the ORM as intended?  The ability to use field lookup syntax with foreign key fields is incredibly powerful. Probably worth the refactor time. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/79205116-E740-4782-A832-F65563669A38%40fattuba.com.

苏子阔

unread,
Nov 25, 2024, 8:45:40 PM11/25/24
to Django users
Thank you very much for your reply!
Not using foreign keys in the model is mainly to simplify the difficulty of repairing data.
Manually aggregate associated data in the view.
But now, due to the business related to exporting data, using association queries may be better/faster.
But I cannot change the data model class arbitrarily.
Reply all
Reply to author
Forward
0 new messages