Skip to content
  • Author Maintainer

    Seems to work:

    [126] pry(main)> cte.apply_to(base.model.all).first
      Clusters::Cluster Load (2.0ms)  WITH RECURSIVE "base_and_ancestors" AS (SELECT clusters.*, namespaces.parent_id AS group_parent_id FROM "clusters" INNER JOIN "cluster_groups" ON "cluster_groups"."cluster_id" = "clusters"."id" INNER JOIN "namespaces" ON "namespaces"."id" = "cluster_groups"."group_id" AND "namespaces"."type" IN ('Group') WHERE "namespaces"."type" IN ('Group') AND "namespaces"."id" = 60
    UNION
    SELECT clusters.*, namespaces.parent_id AS group_parent_id FROM "base_and_ancestors", "clusters" INNER JOIN "cluster_groups" ON "cluster_groups"."cluster_id" = "clusters"."id" INNER JOIN "namespaces" ON "namespaces"."id" = "cluster_groups"."group_id" AND "namespaces"."type" IN ('Group') WHERE "namespaces"."id" = "base_and_ancestors"."group_parent_id") SELECT  "clusters".* FROM "base_and_ancestors" AS "clusters" ORDER BY "clusters"."id" ASC LIMIT $1  [["LIMIT", 1]]
       (pry):125
    => #<Clusters::Cluster:0x00007fb327a80bd8
     id: 43,
     user_id: 1,
     provider_type: "user",
     platform_type: "kubernetes",
     created_at: Thu, 20 Jun 2019 11:11:31 UTC +00:00,
     updated_at: Thu, 20 Jun 2019 11:11:31 UTC +00:00,
     enabled: true,
     name: "woww",
     environment_scope: "*",
     cluster_type: "group_type",
     domain: nil,
     managed: false>
    [133] pry(main)> cte.apply_to(base.model.all).first.group
    
    => #<Group id:60 @hello/woww>
    Edited by Thong Kuah
  • Author Maintainer
    [134] pry(main)> cte.apply_to(base.model.all).last
      Clusters::Cluster Load (1.5ms)  WITH RECURSIVE "base_and_ancestors" AS (SELECT clusters.*, namespaces.parent_id AS group_parent_id FROM "clusters" INNER JOIN "cluster_groups" ON "cluster_groups"."cluster_id" = "clusters"."id" INNER JOIN "namespaces" ON "namespaces"."id" = "cluster_groups"."group_id" AND "namespaces"."type" IN ('Group') WHERE "namespaces"."type" IN ('Group') AND "namespaces"."id" = 60
    UNION
    SELECT clusters.*, namespaces.parent_id AS group_parent_id FROM "base_and_ancestors", "clusters" INNER JOIN "cluster_groups" ON "cluster_groups"."cluster_id" = "clusters"."id" INNER JOIN "namespaces" ON "namespaces"."id" = "cluster_groups"."group_id" AND "namespaces"."type" IN ('Group') WHERE "namespaces"."id" = "base_and_ancestors"."group_parent_id") SELECT  "clusters".* FROM "base_and_ancestors" AS "clusters" ORDER BY "clusters"."id" DESC LIMIT $1  [["LIMIT", 1]]
       (pry):132
    => #<Clusters::Cluster:0x00007fb323ddeb30
     id: 44,
     user_id: 1,
     provider_type: "user",
     platform_type: "kubernetes",
     created_at: Thu, 20 Jun 2019 11:11:45 UTC +00:00,
     updated_at: Thu, 20 Jun 2019 11:11:45 UTC +00:00,
     enabled: true,
     name: "hello",
     environment_scope: "*",
     cluster_type: "group_type",
     domain: nil,
     managed: false>
    [135] pry(main)> cte.apply_to(base.model.all).last.group
    
    => #<Group id:59 @hello>
    Edited by Thong Kuah
  • Author Maintainer
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment