Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.74 KB | None | 0 0
  1. Hello, I'm using cake v1.2.1.8004, got pretty complicated model relations defined. Esp have this relation: Member has many and belongs to many TrainingEvent, the joining table has entries with score (field name points) earned by member. Now I want to add another condition to already complicated search query that will ask if sum of member's points is within specific range (having sum(points) between x and y). Please throw me some tips how to "ask that question" in cake style (association arrays of conditions) for use with paginate. Below is the table structure:
  2.  
  3.  
  4.  
  5. CREATE TABLE IF NOT EXISTS `oiu_members` (
  6.   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  7.   `user_id` int(11) DEFAULT NULL,
  8.   `house_id` int(11) DEFAULT NULL,
  9.   `numer_ewid` varchar(20) COLLATE utf8_polish_ci DEFAULT NULL,
  10.   `ne_text` varchar(5) COLLATE utf8_polish_ci DEFAULT NULL,
  11.   `ne_num` int(10) DEFAULT NULL,
  12.   `data_urodzenia` date DEFAULT NULL,
  13.   `principle_id` tinyint(1) DEFAULT NULL,
  14.   `data_przyjecia` date DEFAULT NULL,
  15.   `czy_postepowanie` tinyint(1) DEFAULT NULL,
  16.   `data_postepowania` date DEFAULT NULL,
  17.   `czy_egzamin` tinyint(1) DEFAULT NULL,
  18.   `data_egzaminu` date DEFAULT NULL,
  19.   `nazwisko_rodowe` varchar(50) COLLATE utf8_polish_ci DEFAULT NULL,
  20.   `imiona_rodzicow` varchar(50) COLLATE utf8_polish_ci DEFAULT NULL,
  21.   `miejsce_urodzenia` varchar(100) COLLATE utf8_polish_ci DEFAULT NULL,
  22.   `obywatelstwo` varchar(50) COLLATE utf8_polish_ci DEFAULT NULL,
  23.   `pesel` varchar(11) COLLATE utf8_polish_ci DEFAULT NULL,
  24.   `nip` varchar(20) COLLATE utf8_polish_ci DEFAULT NULL,
  25.   `aktualny_status` varchar(50) COLLATE utf8_polish_ci DEFAULT NULL,
  26.   `aktualny_status_id` int(11) unsigned DEFAULT NULL,
  27.   `aktualny_status_od` date DEFAULT NULL,
  28.   `default_title` varchar(32) COLLATE utf8_polish_ci DEFAULT NULL,
  29.   PRIMARY KEY (`id`),
  30.   KEY `house_id` (`house_id`),
  31.   KEY `user_id` (`user_id`),
  32.   KEY `aktualny_status_id` (`aktualny_status_id`)
  33. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci ROW_FORMAT=DYNAMIC AUTO_INCREMENT=2432 ;
  34.  
  35. CREATE TABLE IF NOT EXISTS `oiu_members_training_events` (
  36.   `id` int(11) NOT NULL AUTO_INCREMENT,
  37.   `oiu_member_id` int(11) NOT NULL,
  38.   `training_event_id` int(11) NOT NULL,
  39.   `points` int(6) NOT NULL DEFAULT '0',
  40.   PRIMARY KEY (`id`),
  41.   UNIQUE KEY `uniq` (`oiu_member_id`,`training_event_id`)
  42. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
  43.  
  44.  
  45. CREATE TABLE IF NOT EXISTS `training_events` (
  46.   `id` int(11) NOT NULL AUTO_INCREMENT,
  47.   `title` varchar(255) CHARACTER SET utf8 NOT NULL,
  48.   `descr` text CHARACTER SET utf8 NOT NULL,
  49.   `date` datetime NOT NULL,
  50.   `location` text CHARACTER SET utf8 NOT NULL,
  51.   `points` int(11) NOT NULL,
  52.   PRIMARY KEY (`id`)
  53. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement