Skip to content

Instantly share code, notes, and snippets.

@silenius
Created June 14, 2021 10:18
Show Gist options
  • Save silenius/3c090ee9470a4889e9812f7d8da64f56 to your computer and use it in GitHub Desktop.
Save silenius/3c090ee9470a4889e9812f7d8da64f56 to your computer and use it in GitHub Desktop.
SELECT
content.id AS content_id,
content.content_type_id AS content_content_type_id,
content.container_id AS content_container_id,
document.content_id AS document_content_id,
document.some_doc_col AS document_some_doc_col,
document_translation.language_id AS document_transl ation_language_id,
content_translation.language_id AS content_translation_language_id,
document_translation.content_id AS document_translation_content_id,
content_translation.content_id AS content_translation_content_id,
content_translation.title AS content_translation_title,
content _translation.description AS content_translation_description,
(
SELECT
content.content_type_id
FROM
content
JOIN
document
ON content.id = document.content_id
WHERE
content_translation.content_id = content.id
)
AS _sa_polymorphic_on,
document_translation.body AS document_translation_body,
content_type_1.id AS content_type_1_id,
content_type_1.name AS content_type_1_name
FROM
document_translation,
content_translation,
content
JOIN
document
ON content.id = document.content_id
JOIN
(
SELECT
document_translation.language_id AS document_translation_language_id,
content_translation.language_id AS content_translation_language_id,
document_translation.conten t_id AS document_translation_content_id,
content_translation.content_id AS content_translation_content_id,
content_translation.title AS content_translation_title,
content_translation.description AS content_translation_description,
(
SELECT
content.content_type_id
FROM
content
WHERE
content_translation.content_id = content.id
)
AS _sa_polymorphic_on,
document_translation.body AS document_translation_body,
row_number() OVER (PARTITION BY document_translation.content_id
ORDER BY
document_translation.language_id = ? DESC, document_translation.language_id = ? D ESC) AS "index"
FROM
content_translation
JOIN
document_translation
ON content_translation.language_id = document_translation.language_id
AND content_translation.content_id = document_translation.content_id
WHERE
document_translation.language_id IN
(
?,
?
)
)
AS anon_1
ON anon_1.document_translation_content_id = content.id
AND anon_1."index" = ?
JOIN
content_type AS content_type_1
ON content_type_1.id = content.content_type_id
WHERE
content_translation.title LIKE ?
ORDER BY
content_translation.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment