Skip to content

I need to create a table with m2m field references to itself #265

Answered by sinisaos
serg-yalosovetsky asked this question in Q&A
Discussion options

You must be logged in to vote

@serg-yalosovetsky Based on this old discussion, I don't think that's possible right now. Maybe you can patch your local Piccolo installation to try this out and see if this suits your needs.

# in piccolo/columns/m2m.py
def get_select_string(self, engine_type: str, with_alias=True) -> str:
    m2m_table_name_with_schema = (
        self.m2m._meta.resolved_joining_table._meta.get_formatted_tablename()  # noqa: E501
    )  # noqa: E501
    m2m_relationship_name = self.m2m._meta.name

    fk_1 = self.m2m._meta.primary_foreign_key
    fk_1_name = fk_1._meta.db_column_name
    table_1 = fk_1._foreign_key_meta.resolved_references
    table_1_name = table_1._meta.tablename
    table_1_name_with_…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@sinisaos
Comment options

@serg-yalosovetsky
Comment options

@sinisaos
Comment options

sinisaos Feb 2, 2024
Collaborator

@sinisaos
Comment options

sinisaos Feb 3, 2024
Collaborator

@serg-yalosovetsky
Comment options

Answer selected by serg-yalosovetsky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants