_db->select(); $select->from($this->_getPair('GalleryImage'), 'COUNT(`GalleryImage`.`id`)'); $select->where('`GalleryImage`.`galleryId` = `Gallery`.`id`'); if (null !== $visible) { $select->where('`GalleryImage`.`enabled` = ?', ($visible) ? 'y' : 'n'); } return $select; } }