M2M and Joining tables that are in schemas #841
Answered
by
dantownsend
quinnalfaro
asked this question in
Q&A
-
Hey there!
|
Beta Was this translation helpful? Give feedback.
Answered by
dantownsend
Jun 19, 2023
Replies: 2 comments 6 replies
-
That's a good point. We recently added support for Postgres schemas, and it looks like M2M might be something we overlooked. It just seems to be using the table name, without the schema name. piccolo/piccolo/columns/m2m.py Line 66 in cd5595c It's quite a simple fix though - will turn this into an issue. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@dantownsend I just tried that and just need to add the schema name in m2m inner_select like this and everything works, but that need to be checked. m2m_table_schema = (
self.m2m._meta.resolved_joining_table._meta.schema or "public"
)
inner_select = f"""
"{m2m_table_schema}"."{m2m_table_name}"
JOIN "{m2m_table_schema}"."{table_1_name}" "inner_{table_1_name}" ON (
"{m2m_table_schema}"."{m2m_table_name}"."{fk_1_name}" = "inner_{table_1_name}"."{table_1_pk_name}"
)
JOIN "{m2m_table_schema}"."{table_2_name}" "inner_{table_2_name}" ON (
"{m2m_table_schema}"."{m2m_table_name}"."{fk_2_name}" = "inner_{table_2_name}"."{table_2_pk_name}"
)
WHERE "{m2m_table_schema}"."{m2m_table_name}"."{fk_1_name}" = "{m2m_table_schema}"."{table_1_name}"."{table_1_pk_name}"
""" # noqa: E501 |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be fixed now in
piccolo==0.115.0
.