I’m currently programming a Bug Tracker.
I have a table called bug_states. The revelant field is closed which is an TINYINT if it’s set to 0 than this would say that the bug state marks the bug as unclosed (open). If it’s set to 1 than this would say that the bug state marks the bug as closed.
Than I have a table called milestones it’s structure isn’t really relevant for this problem.
Than I have a last table called bugs. The revelant fields here are bug_state_id which is used by cakephp to create an association to the bug_states table and milestone_id which is used to associate the bug to a milestone.
Now I wan’t to count how many bugs are open for a given milestone.
As Example, this is my code to get all bugs for a given milestone:
$total_bug_count = $this->Bug->find('count', array('conditions' => array('Bug.milestone_id' => $milestone_id)));
Does anyone know how I can count only the bugs which are open (that are those who have BugState.closed = 0)?
(If something is unclear, just say it ;-))
The solution was so simple (and I tried it so long…):