Created
May 4, 2013 19:17
-
-
Save kylejohnson/5518438 to your computer and use it in GitHub Desktop.
Attempting to return the event count on a per-monitor basis (lines 8-10 of the first file), instead its doing a count() on all monitors. The last file shows the query that is being run - why isn't WHERE `Event`.`MonitorId` IN ('1', '2') being appended to the query such as is for the find on line 6?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Event extends AppModel { | |
| public $useTable = 'Events'; | |
| public $belongsTo = array( | |
| 'Monitor' => array( | |
| 'className' => 'Monitor', | |
| 'foreignKey' => 'MonitorId' | |
| ) | |
| ); | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kjohnson@zoneminder:~/ZoneMinder/web/app/Model$ cat Monitor.php | |
| <?php | |
| class Monitor extends AppModel { | |
| public $useTable = 'Monitors'; | |
| public $hasMany = array( | |
| 'Event' => array( | |
| 'className' => 'Event', | |
| 'foreignKey' => 'MonitorId' | |
| ), | |
| 'Zone' => array( | |
| 'className' => 'Zone', | |
| 'foreignKey' => 'MonitorId' | |
| ) | |
| ); | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class MonitorsController extends AppController { | |
| public function index() { | |
| $monitoroptions['fields'] = array('Name', 'Id', 'Function', 'Host'); | |
| $this->set('monitors', $this->Monitor->find('all', $monitoroptions)); | |
| $elhoptions['conditions'] = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR)'); | |
| $elhoptions['fields'] = array('Event.Id'); | |
| $this->set('elh', $this->Monitor->Event->find('count', $elhoptions)); | |
| } | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT COUNT(*) AS `count` FROM `zm`.`Events` AS `Event` LEFT JOIN `zm`.`Monitors` AS `Monitor` ON (`Event`.`MonitorId` = `Monitor`.`id`) WHERE `Event`.`StartTime` > DATE_SUB(NOW(), INTERVAL 1 HOUR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment