1

Okay, what I've got is two models...

Jiraissue:

class Jiraissue < ActiveRecord::Base
  # JIRA uses a singular table name for this model
  set_table_name 'jiraissue'
  has_one :severity
end

Severity:

class Severity < ActiveRecord::Base
  belongs_to :jiraissue
end

What I'm trying to do is get a count of all Jiraissues for which jiraissue.severity = "S1"

Now it turns out that the jiraissue table has a column for priority so I can pull this trick in the model...

Jiraissue:

class Jiraissue < ActiveRecord::Base
  # JIRA uses a singular table name for this model
  set_table_name 'jiraissue'
  has_one :severity

  def self.count_priority(priority)
    where("PRIORITY = ?",priority).count()
  end

end

And then in the view do something like...

<%= (1..4).map {
  |priority| Jiraissue.biit.bugs.recent.count_priority(priority)
  }.inspect %>

How do I do something similar for Jiraissue to get a count_severity method?

This just doesn't work (nor would I expect it to)...

  def self.count_severity(severity)
    where("severity = ?",severity).count()
  end

But I'm totally confused.

bdon
  • 2,068
  • 17
  • 15
Bruce P. Henry
  • 412
  • 1
  • 4
  • 14
  • Me too totally confused ;)... ` jiraissue.severity` will return an association object of `Severity` class right? How do you compare `jiraissue.severity = "S1"`? – nkm Feb 18 '12 at 04:10

2 Answers2

0
Jiraissue.joins(:severities).where(:severities => {:severity => "S1"}).count
bdon
  • 2,068
  • 17
  • 15
  • Hooray!! Jiraissue.joins(:severity).where(:severities => {:severity => "S1"}).count This TOTALLY works! Thanks for getting me on the right path! – Bruce P. Henry Feb 23 '12 at 22:45
0

model

def self.count_priority(priority)
  where("PRIORITY = ?",priority).size
end

controller

def index
  @jiraissues = Jiraissue.count_priority('S1')
end

Doesn't it work?

Kleber S.
  • 8,110
  • 6
  • 43
  • 69
  • Nope, that won't work because priority is not a column in the jiraissue table. I'm thinking bdon's answer might be just what I'm looking for. – Bruce P. Henry Feb 21 '12 at 16:43