piccolo-orm / piccolo_admin

A powerful web admin for your database.
https://piccolo-orm.com/ecosystem/
MIT License
299 stars 35 forks source link

Piccolo-Admin incorrectly registers ForeignKey references as Tables #361

Open aabmets opened 4 months ago

aabmets commented 4 months ago

Given the following table definitions:

class ElementsTable(Table, tablename="meta_elements", schema=AppConfig.DB_SCHEMA):
    classification_code = ForeignKey(
        references=ClassificationsTable,
        target_column=ClassificationsTable.code,
        on_delete=OnDelete.cascade,
        on_update=OnUpdate.cascade,
        required=True,
        null=False
    )

class ClassificationsTable(Table, tablename="meta_classifications", schema=AppConfig.DB_SCHEMA):
    ...

# other tables omitted due to irrelevance

Piccolo-admin produces the following output in the web GUI: image

You can witness the double "Meta Classifications" table in the tables list.
I have verified, that when the ForeignKey column type is replaced with any other column type (Varchar, Integer, etc.),
a duplicate entry is not introduced into the tables list of the admin web GUI.