diff --git a/lib/miq_expression.rb b/lib/miq_expression.rb
index b080c59d114..e58ec1eb863 100644
--- a/lib/miq_expression.rb
+++ b/lib/miq_expression.rb
@@ -620,9 +620,9 @@ def self.operands2rubyvalue(operator, ops, context_type)
end
end
elsif ops["count"]
- ref, count = value2tag(ops["count"])
- field = "#{count}"
- [field, quote(ops["value"], "integer")]
+ target = parse_field_or_tag(ops["count"])
+ fld = "#{target.tag_path_with}"
+ [fld, quote(ops["value"], target.column_type)]
elsif ops["regkey"]
if operator == "key exists"
"#{ops["regkey"].strip} == 'true'"
diff --git a/lib/miq_expression/count_field.rb b/lib/miq_expression/count_field.rb
index b66d6f560c2..1f84a41dbde 100644
--- a/lib/miq_expression/count_field.rb
+++ b/lib/miq_expression/count_field.rb
@@ -22,6 +22,10 @@ def to_s
[model, *associations].join(".")
end
+ def column_type
+ :integer
+ end
+
private
def tag_values
diff --git a/spec/lib/miq_expression_spec.rb b/spec/lib/miq_expression_spec.rb
index 49a5f1fc171..c458b408ca6 100644
--- a/spec/lib/miq_expression_spec.rb
+++ b/spec/lib/miq_expression_spec.rb
@@ -967,7 +967,7 @@
describe "#to_ruby" do
it "generates the ruby for a = expression with count" do
- actual = described_class.new("=" => {"count" => "Vm-snapshots", "value" => "1"}).to_ruby
+ actual = described_class.new("=" => {"count" => "Vm.snapshots", "value" => "1"}).to_ruby
expected = "/virtual/snapshots == 1"
expect(actual).to eq(expected)
end
@@ -985,7 +985,7 @@
end
it "generates the ruby for a < expression with count" do
- actual = described_class.new("<" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
+ actual = described_class.new("<" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "/virtual/snapshots < 2"
expect(actual).to eq(expected)
end
@@ -997,7 +997,7 @@
end
it "generates the ruby for a > expression with count" do
- actual = described_class.new(">" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
+ actual = described_class.new(">" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "/virtual/snapshots > 2"
expect(actual).to eq(expected)
end
@@ -1009,7 +1009,7 @@
end
it "generates the ruby for a >= expression with count" do
- actual = described_class.new(">=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
+ actual = described_class.new(">=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "/virtual/snapshots >= 2"
expect(actual).to eq(expected)
end
@@ -1021,7 +1021,7 @@
end
it "generates the ruby for a <= expression with count" do
- actual = described_class.new("<=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
+ actual = described_class.new("<=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "/virtual/snapshots <= 2"
expect(actual).to eq(expected)
end
@@ -1033,7 +1033,7 @@
end
it "generates the ruby for a != expression with count" do
- actual = described_class.new("!=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
+ actual = described_class.new("!=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "/virtual/snapshots != 2"
expect(actual).to eq(expected)
end