Repository navigation
Conversation
| @@ -545,6 +545,32 @@ | |||
| end | |||
| end | |||
|
|
|||
| describe "#v_total_direct_service_children" do | |||
There was a problem hiding this comment.
"direct" in our parlance means "directly under the service", so in the example tree below there are only 2 direct service children, c1, and c2. Are you looking for all service children (i.e. the entire tree?)
There was a problem hiding this comment.
Ok yeah - spoke with @GilbertCherrie and that is what this is doing - the test didn't make that clear to me.
|
@miq-bot add-label tal/yes? |
c2bc6ad to
8b48ed8
Compare
|
I'm going to merge this as is, however I want to follow up with the ancestry gem and see if we can find a way to expose it there instead, because it's really a concern for that gem. Spoke to @kbrock about it briefly, and he agreed, though we're not actually sure how to structure that, hence merging this as is. |
|
Checked commits GilbertCherrie/manageiq@b34a429~...8b48ed8 with ruby 3.3.12, rubocop 1.91.0, haml-lint 0.78.0, and yamllint 1.37.1 |
|
Backported to |
…ice-children-virtual-total Add v_total_direct_service_children virtual total to Service model (cherry picked from commit 27efecc)
This PR is required for: ManageIQ/manageiq-ui-service#2215 and ManageIQ/manageiq-api#1345
Add v_total_direct_service_children virtual total to Service
Adds a new SQL-backed virtual total v_total_direct_service_children to the Service model that counts the number of direct (first-level) service children for a given service record.
What it does:
Uses an Arel subquery against the services table to count child records whose ancestry exactly matches the current record's ancestry path
Handles both root services (no ancestry) and nested services (with ancestry) via a CASE expression
Returns 0 (via COALESCE) when no direct children exist
Supports SQL-level evaluation (via SELECT) and falls back to Ruby-level evaluation
Tests added:
SQL path: verifies v_total_direct_service_children is populated correctly when selected via Service.select(:id, :v_total_direct_service_children)
Ruby path: verifies the attribute is computed in Ruby when not SQL-selected, and confirms attribute_present? returns false in that case