From 67c1bc6b1c0b9fb29a588626b705e82a31eecece Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 19 Jun 2023 01:25:31 +0200 Subject: [PATCH] Selecting parent and grantparent networks in entity releases filter. --- assets/js/entities/actions.js | 30 ++++++++++++++++------- migrations/20190325001339_releases.js | 34 +++++++++++++-------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/assets/js/entities/actions.js b/assets/js/entities/actions.js index afdfa0c7..a9d36774 100755 --- a/assets/js/entities/actions.js +++ b/assets/js/entities/actions.js @@ -90,14 +90,28 @@ function initEntitiesActions(store, router) { offset: $offset orderBy: $orderBy filter: { - entity: { - slug: { - equalTo: $entitySlug - } - type: { - equalTo: $entityType - } - } + entity: { + or: [ + { + slug: { equalTo: $entitySlug } + type: { equalTo: $entityType } + } + { + parent:{ + slug: { equalTo: $entitySlug } + type: { equalTo: $entityType } + } + } + { + parent:{ + parent: { + slug: { equalTo: $entitySlug } + type: { equalTo: $entityType } + } + } + } + ] + } effectiveDate: { lessThan: $before, greaterThan: $after diff --git a/migrations/20190325001339_releases.js b/migrations/20190325001339_releases.js index a7451343..e806923f 100755 --- a/migrations/20190325001339_releases.js +++ b/migrations/20190325001339_releases.js @@ -1738,23 +1738,23 @@ exports.up = (knex) => Promise.resolve() WHERE releases.entity_id = entity.id; $$ LANGUAGE SQL STABLE; - CREATE FUNCTION entities_scene_tags(entity entities, selectable_tags text[]) RETURNS SETOF tags AS $$ - SELECT tags.* - FROM releases - LEFT JOIN - releases_tags ON releases_tags.release_id = releases.id - LEFT JOIN - tags ON tags.id = releases_tags.tag_id - WHERE - releases.entity_id = entity.id - AND - CASE WHEN array_length(selectable_tags, 1) IS NOT NULL - THEN tags.slug = ANY(selectable_tags) - ELSE true - END - GROUP BY tags.id - ORDER BY tags.name; - $$ LANGUAGE SQL STABLE; + CREATE FUNCTION entities_scene_tags(entity entities, selectable_tags text[]) RETURNS SETOF tags AS $$ + SELECT tags.* + FROM releases + LEFT JOIN + releases_tags ON releases_tags.release_id = releases.id + LEFT JOIN + tags ON tags.id = releases_tags.tag_id + WHERE + releases.entity_id = entity.id + AND + CASE WHEN array_length(selectable_tags, 1) IS NOT NULL + THEN tags.slug = ANY(selectable_tags) + ELSE true + END + GROUP BY tags.id + ORDER BY tags.name; + $$ LANGUAGE SQL STABLE; /* GraphQL/Postgraphile 'every' applies to the data, will only include scenes for which every assigned tag is selected, instead of what we want; scenes with every selected tag, but possibly also some others */