PageRenderTime 73ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/cake/tests/cases/libs/model/model_read.test.php

https://bitbucket.org/webpolis/hurli
PHP | 7456 lines | 6784 code | 326 blank | 346 comment | 24 complexity | 2cd3a3cc5297beb0d6137e2610f2f396 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * ModelReadTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake
  16. * @subpackage cake.tests.cases.libs.model
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. require_once dirname(__FILE__) . DS . 'model.test.php';
  21. /**
  22. * ModelReadTest
  23. *
  24. * @package cake
  25. * @subpackage cake.tests.cases.libs.model.operations
  26. */
  27. class ModelReadTest extends BaseModelTest {
  28. /**
  29. * testFetchingNonUniqueFKJoinTableRecords()
  30. *
  31. * Tests if the results are properly returned in the case there are non-unique FK's
  32. * in the join table but another fields value is different. For example:
  33. * something_id | something_else_id | doomed = 1
  34. * something_id | something_else_id | doomed = 0
  35. * Should return both records and not just one.
  36. *
  37. * @access public
  38. * @return void
  39. */
  40. function testFetchingNonUniqueFKJoinTableRecords() {
  41. $this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
  42. $Something = new Something();
  43. $joinThingData = array(
  44. 'JoinThing' => array(
  45. 'something_id' => 1,
  46. 'something_else_id' => 2,
  47. 'doomed' => '0',
  48. 'created' => '2007-03-18 10:39:23',
  49. 'updated' => '2007-03-18 10:41:31'
  50. )
  51. );
  52. $Something->JoinThing->create($joinThingData);
  53. $Something->JoinThing->save();
  54. $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
  55. $this->assertEqual($result[0]['JoinThing']['doomed'], true);
  56. $this->assertEqual($result[1]['JoinThing']['doomed'], false);
  57. $result = $Something->find('first');
  58. $this->assertEqual(count($result['SomethingElse']), 2);
  59. $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']);
  60. $this->assertTrue(in_array(true, $doomed));
  61. $this->assertTrue(in_array(false, $doomed));
  62. }
  63. /**
  64. * testGroupBy method
  65. *
  66. * These tests will never pass with Postgres or Oracle as all fields in a select must be
  67. * part of an aggregate function or in the GROUP BY statement.
  68. *
  69. * @access public
  70. * @return void
  71. */
  72. function testGroupBy() {
  73. $db = ConnectionManager::getDataSource('test_suite');
  74. $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle'));
  75. $message = '%s Postgres and Oracle have strict GROUP BY and are incompatible with this test.';
  76. if ($this->skipIf($isStrictGroupBy, $message )) {
  77. return;
  78. }
  79. $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid');
  80. $Thread =& new Thread();
  81. $Product =& new Product();
  82. $result = $Thread->find('all', array(
  83. 'group' => 'Thread.project_id',
  84. 'order' => 'Thread.id ASC'
  85. ));
  86. $expected = array(
  87. array(
  88. 'Thread' => array(
  89. 'id' => 1,
  90. 'project_id' => 1,
  91. 'name' => 'Project 1, Thread 1'
  92. ),
  93. 'Project' => array(
  94. 'id' => 1,
  95. 'name' => 'Project 1'
  96. ),
  97. 'Message' => array(
  98. array(
  99. 'id' => 1,
  100. 'thread_id' => 1,
  101. 'name' => 'Thread 1, Message 1'
  102. ))),
  103. array(
  104. 'Thread' => array(
  105. 'id' => 3,
  106. 'project_id' => 2,
  107. 'name' => 'Project 2, Thread 1'
  108. ),
  109. 'Project' => array(
  110. 'id' => 2,
  111. 'name' => 'Project 2'
  112. ),
  113. 'Message' => array(
  114. array(
  115. 'id' => 3,
  116. 'thread_id' => 3,
  117. 'name' => 'Thread 3, Message 1'
  118. ))));
  119. $this->assertEqual($result, $expected);
  120. $rows = $Thread->find('all', array(
  121. 'group' => 'Thread.project_id',
  122. 'fields' => array('Thread.project_id', 'COUNT(*) AS total')
  123. ));
  124. $result = array();
  125. foreach($rows as $row) {
  126. $result[$row['Thread']['project_id']] = $row[0]['total'];
  127. }
  128. $expected = array(
  129. 1 => 2,
  130. 2 => 1
  131. );
  132. $this->assertEqual($result, $expected);
  133. $rows = $Thread->find('all', array(
  134. 'group' => 'Thread.project_id',
  135. 'fields' => array('Thread.project_id', 'COUNT(*) AS total'),
  136. 'order'=> 'Thread.project_id'
  137. ));
  138. $result = array();
  139. foreach($rows as $row) {
  140. $result[$row['Thread']['project_id']] = $row[0]['total'];
  141. }
  142. $expected = array(
  143. 1 => 2,
  144. 2 => 1
  145. );
  146. $this->assertEqual($result, $expected);
  147. $result = $Thread->find('all', array(
  148. 'conditions' => array('Thread.project_id' => 1),
  149. 'group' => 'Thread.project_id'
  150. ));
  151. $expected = array(
  152. array(
  153. 'Thread' => array(
  154. 'id' => 1,
  155. 'project_id' => 1,
  156. 'name' => 'Project 1, Thread 1'
  157. ),
  158. 'Project' => array(
  159. 'id' => 1,
  160. 'name' => 'Project 1'
  161. ),
  162. 'Message' => array(
  163. array(
  164. 'id' => 1,
  165. 'thread_id' => 1,
  166. 'name' => 'Thread 1, Message 1'
  167. ))));
  168. $this->assertEqual($result, $expected);
  169. $result = $Thread->find('all', array(
  170. 'conditions' => array('Thread.project_id' => 1),
  171. 'group' => 'Thread.project_id, Project.id'
  172. ));
  173. $this->assertEqual($result, $expected);
  174. $result = $Thread->find('all', array(
  175. 'conditions' => array('Thread.project_id' => 1),
  176. 'group' => 'project_id'
  177. ));
  178. $this->assertEqual($result, $expected);
  179. $result = $Thread->find('all', array(
  180. 'conditions' => array('Thread.project_id' => 1),
  181. 'group' => array('project_id')
  182. ));
  183. $this->assertEqual($result, $expected);
  184. $result = $Thread->find('all', array(
  185. 'conditions' => array('Thread.project_id' => 1),
  186. 'group' => array('project_id', 'Project.id')
  187. ));
  188. $this->assertEqual($result, $expected);
  189. $result = $Thread->find('all', array(
  190. 'conditions' => array('Thread.project_id' => 1),
  191. 'group' => array('Thread.project_id', 'Project.id')
  192. ));
  193. $this->assertEqual($result, $expected);
  194. $expected = array(
  195. array('Product' => array('type' => 'Clothing'), array('price' => 32)),
  196. array('Product' => array('type' => 'Food'), array('price' => 9)),
  197. array('Product' => array('type' => 'Music'), array( 'price' => 4)),
  198. array('Product' => array('type' => 'Toy'), array('price' => 3))
  199. );
  200. $result = $Product->find('all',array(
  201. 'fields'=>array('Product.type', 'MIN(Product.price) as price'),
  202. 'group'=> 'Product.type',
  203. 'order' => 'Product.type ASC'
  204. ));
  205. $this->assertEqual($result, $expected);
  206. $result = $Product->find('all', array(
  207. 'fields'=>array('Product.type', 'MIN(Product.price) as price'),
  208. 'group'=> array('Product.type'),
  209. 'order' => 'Product.type ASC'));
  210. $this->assertEqual($result, $expected);
  211. }
  212. /**
  213. * testOldQuery method
  214. *
  215. * @access public
  216. * @return void
  217. */
  218. function testOldQuery() {
  219. $this->loadFixtures('Article');
  220. $Article =& new Article();
  221. $query = 'SELECT title FROM ';
  222. $query .= $this->db->fullTableName('articles');
  223. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)';
  224. $results = $Article->query($query);
  225. $this->assertTrue(is_array($results));
  226. $this->assertEqual(count($results), 2);
  227. $query = 'SELECT title, body FROM ';
  228. $query .= $this->db->fullTableName('articles');
  229. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1';
  230. $results = $Article->query($query, false);
  231. $this->assertTrue(!isset($this->db->_queryCache[$query]));
  232. $this->assertTrue(is_array($results));
  233. $query = 'SELECT title, id FROM ';
  234. $query .= $this->db->fullTableName('articles');
  235. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  236. $query .= '.published = ' . $this->db->value('Y');
  237. $results = $Article->query($query, true);
  238. $this->assertTrue(isset($this->db->_queryCache[$query]));
  239. $this->assertTrue(is_array($results));
  240. }
  241. /**
  242. * testPreparedQuery method
  243. *
  244. * @access public
  245. * @return void
  246. */
  247. function testPreparedQuery() {
  248. $this->loadFixtures('Article');
  249. $Article =& new Article();
  250. $this->db->_queryCache = array();
  251. $finalQuery = 'SELECT title, published FROM ';
  252. $finalQuery .= $this->db->fullTableName('articles');
  253. $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles');
  254. $finalQuery .= '.id = ' . $this->db->value(1);
  255. $finalQuery .= ' AND ' . $this->db->fullTableName('articles');
  256. $finalQuery .= '.published = ' . $this->db->value('Y');
  257. $query = 'SELECT title, published FROM ';
  258. $query .= $this->db->fullTableName('articles');
  259. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  260. $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?';
  261. $params = array(1, 'Y');
  262. $result = $Article->query($query, $params);
  263. $expected = array(
  264. '0' => array(
  265. $this->db->fullTableName('articles', false) => array(
  266. 'title' => 'First Article', 'published' => 'Y')
  267. ));
  268. if (isset($result[0][0])) {
  269. $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)];
  270. unset($expected[0][$this->db->fullTableName('articles', false)]);
  271. }
  272. $this->assertEqual($result, $expected);
  273. $this->assertTrue(isset($this->db->_queryCache[$finalQuery]));
  274. $finalQuery = 'SELECT id, created FROM ';
  275. $finalQuery .= $this->db->fullTableName('articles');
  276. $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles');
  277. $finalQuery .= '.title = ' . $this->db->value('First Article');
  278. $query = 'SELECT id, created FROM ';
  279. $query .= $this->db->fullTableName('articles');
  280. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?';
  281. $params = array('First Article');
  282. $result = $Article->query($query, $params, false);
  283. $this->assertTrue(is_array($result));
  284. $this->assertTrue(
  285. isset($result[0][$this->db->fullTableName('articles', false)])
  286. || isset($result[0][0])
  287. );
  288. $this->assertFalse(isset($this->db->_queryCache[$finalQuery]));
  289. $query = 'SELECT title FROM ';
  290. $query .= $this->db->fullTableName('articles');
  291. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?';
  292. $params = array('%First%');
  293. $result = $Article->query($query, $params);
  294. $this->assertTrue(is_array($result));
  295. $this->assertTrue(
  296. isset($result[0][$this->db->fullTableName('articles', false)]['title'])
  297. || isset($result[0][0]['title'])
  298. );
  299. //related to ticket #5035
  300. $query = 'SELECT title FROM ';
  301. $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?';
  302. $params = array('First? Article', 'Y');
  303. $Article->query($query, $params);
  304. $expected = 'SELECT title FROM ';
  305. $expected .= $this->db->fullTableName('articles');
  306. $expected .= " WHERE title = 'First? Article' AND published = 'Y'";
  307. $this->assertTrue(isset($this->db->_queryCache[$expected]));
  308. }
  309. /**
  310. * testParameterMismatch method
  311. *
  312. * @access public
  313. * @return void
  314. */
  315. function testParameterMismatch() {
  316. $this->loadFixtures('Article');
  317. $Article =& new Article();
  318. $query = 'SELECT * FROM ' . $this->db->fullTableName('articles');
  319. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  320. $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?';
  321. $params = array('Y');
  322. $this->expectError();
  323. ob_start();
  324. $result = $Article->query($query, $params);
  325. ob_end_clean();
  326. $this->assertEqual($result, null);
  327. }
  328. /**
  329. * testVeryStrangeUseCase method
  330. *
  331. * @access public
  332. * @return void
  333. */
  334. function testVeryStrangeUseCase() {
  335. $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query.";
  336. $message .= " MSSQL is incompatible with this test.";
  337. if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) {
  338. return;
  339. }
  340. $this->loadFixtures('Article');
  341. $Article =& new Article();
  342. $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?';
  343. $param = array(
  344. $this->db->fullTableName('articles'),
  345. $this->db->fullTableName('articles') . '.user_id', '3',
  346. $this->db->fullTableName('articles') . '.published', 'Y'
  347. );
  348. $this->expectError();
  349. ob_start();
  350. $result = $Article->query($query, $param);
  351. ob_end_clean();
  352. }
  353. /**
  354. * testRecursiveUnbind method
  355. *
  356. * @access public
  357. * @return void
  358. */
  359. function testRecursiveUnbind() {
  360. $this->loadFixtures('Apple', 'Sample');
  361. $TestModel =& new Apple();
  362. $TestModel->recursive = 2;
  363. $result = $TestModel->find('all');
  364. $expected = array(
  365. array(
  366. 'Apple' => array (
  367. 'id' => 1,
  368. 'apple_id' => 2,
  369. 'color' => 'Red 1',
  370. 'name' => 'Red Apple 1',
  371. 'created' => '2006-11-22 10:38:58',
  372. 'date' => '1951-01-04',
  373. 'modified' => '2006-12-01 13:31:26',
  374. 'mytime' => '22:57:17'
  375. ),
  376. 'Parent' => array(
  377. 'id' => 2,
  378. 'apple_id' => 1,
  379. 'color' => 'Bright Red 1',
  380. 'name' => 'Bright Red Apple',
  381. 'created' => '2006-11-22 10:43:13',
  382. 'date' => '2014-01-01',
  383. 'modified' => '2006-11-30 18:38:10',
  384. 'mytime' => '22:57:17',
  385. 'Parent' => array(
  386. 'id' => 1,
  387. 'apple_id' => 2,
  388. 'color' => 'Red 1',
  389. 'name' => 'Red Apple 1',
  390. 'created' => '2006-11-22 10:38:58',
  391. 'date' => '1951-01-04',
  392. 'modified' => '2006-12-01 13:31:26',
  393. 'mytime' => '22:57:17'
  394. ),
  395. 'Sample' => array(
  396. 'id' => 2,
  397. 'apple_id' => 2,
  398. 'name' => 'sample2'
  399. ),
  400. 'Child' => array(
  401. array(
  402. 'id' => 1,
  403. 'apple_id' => 2,
  404. 'color' => 'Red 1',
  405. 'name' => 'Red Apple 1',
  406. 'created' => '2006-11-22 10:38:58',
  407. 'date' => '1951-01-04',
  408. 'modified' => '2006-12-01 13:31:26',
  409. 'mytime' => '22:57:17'
  410. ),
  411. array(
  412. 'id' => 3,
  413. 'apple_id' => 2,
  414. 'color' => 'blue green',
  415. 'name' => 'green blue',
  416. 'created' => '2006-12-25 05:13:36',
  417. 'date' => '2006-12-25',
  418. 'modified' => '2006-12-25 05:23:24',
  419. 'mytime' => '22:57:17'
  420. ),
  421. array(
  422. 'id' => 4,
  423. 'apple_id' => 2,
  424. 'color' => 'Blue Green',
  425. 'name' => 'Test Name',
  426. 'created' => '2006-12-25 05:23:36',
  427. 'date' => '2006-12-25',
  428. 'modified' => '2006-12-25 05:23:36',
  429. 'mytime' => '22:57:17'
  430. ))),
  431. 'Sample' => array(
  432. 'id' =>'',
  433. 'apple_id' => '',
  434. 'name' => ''
  435. ),
  436. 'Child' => array(
  437. array(
  438. 'id' => 2,
  439. 'apple_id' => 1,
  440. 'color' => 'Bright Red 1',
  441. 'name' => 'Bright Red Apple',
  442. 'created' => '2006-11-22 10:43:13',
  443. 'date' => '2014-01-01',
  444. 'modified' => '2006-11-30 18:38:10',
  445. 'mytime' => '22:57:17',
  446. 'Parent' => array(
  447. 'id' => 1,
  448. 'apple_id' => 2,
  449. 'color' => 'Red 1',
  450. 'name' => 'Red Apple 1',
  451. 'created' => '2006-11-22 10:38:58',
  452. 'date' => '1951-01-04',
  453. 'modified' => '2006-12-01 13:31:26',
  454. 'mytime' => '22:57:17'
  455. ),
  456. 'Sample' => array(
  457. 'id' => 2,
  458. 'apple_id' => 2,
  459. 'name' => 'sample2'
  460. ),
  461. 'Child' => array(
  462. array(
  463. 'id' => 1,
  464. 'apple_id' => 2,
  465. 'color' => 'Red 1',
  466. 'name' => 'Red Apple 1',
  467. 'created' => '2006-11-22 10:38:58',
  468. 'date' => '1951-01-04',
  469. 'modified' => '2006-12-01 13:31:26',
  470. 'mytime' => '22:57:17'
  471. ),
  472. array(
  473. 'id' => 3,
  474. 'apple_id' => 2,
  475. 'color' => 'blue green',
  476. 'name' => 'green blue',
  477. 'created' => '2006-12-25 05:13:36',
  478. 'date' => '2006-12-25',
  479. 'modified' => '2006-12-25 05:23:24',
  480. 'mytime' => '22:57:17'
  481. ),
  482. array(
  483. 'id' => 4,
  484. 'apple_id' => 2,
  485. 'color' => 'Blue Green',
  486. 'name' => 'Test Name',
  487. 'created' => '2006-12-25 05:23:36',
  488. 'date' => '2006-12-25',
  489. 'modified' => '2006-12-25 05:23:36',
  490. 'mytime' => '22:57:17'
  491. ))))),
  492. array(
  493. 'Apple' => array(
  494. 'id' => 2,
  495. 'apple_id' => 1,
  496. 'color' => 'Bright Red 1',
  497. 'name' => 'Bright Red Apple',
  498. 'created' => '2006-11-22 10:43:13',
  499. 'date' => '2014-01-01',
  500. 'modified' => '2006-11-30 18:38:10',
  501. 'mytime' => '22:57:17'
  502. ),
  503. 'Parent' => array(
  504. 'id' => 1,
  505. 'apple_id' => 2,
  506. 'color' => 'Red 1',
  507. 'name' => 'Red Apple 1',
  508. 'created' => '2006-11-22 10:38:58',
  509. 'date' => '1951-01-04',
  510. 'modified' => '2006-12-01 13:31:26',
  511. 'mytime' => '22:57:17',
  512. 'Parent' => array(
  513. 'id' => 2,
  514. 'apple_id' => 1,
  515. 'color' => 'Bright Red 1',
  516. 'name' => 'Bright Red Apple',
  517. 'created' => '2006-11-22 10:43:13',
  518. 'date' => '2014-01-01',
  519. 'modified' => '2006-11-30 18:38:10',
  520. 'mytime' => '22:57:17'
  521. ),
  522. 'Sample' => array(),
  523. 'Child' => array(
  524. array(
  525. 'id' => 2,
  526. 'apple_id' => 1,
  527. 'color' => 'Bright Red 1',
  528. 'name' => 'Bright Red Apple',
  529. 'created' => '2006-11-22 10:43:13',
  530. 'date' => '2014-01-01',
  531. 'modified' => '2006-11-30 18:38:10',
  532. 'mytime' => '22:57:17'
  533. ))),
  534. 'Sample' => array(
  535. 'id' => 2,
  536. 'apple_id' => 2,
  537. 'name' => 'sample2',
  538. 'Apple' => array(
  539. 'id' => 2,
  540. 'apple_id' => 1,
  541. 'color' => 'Bright Red 1',
  542. 'name' => 'Bright Red Apple',
  543. 'created' => '2006-11-22 10:43:13',
  544. 'date' => '2014-01-01',
  545. 'modified' => '2006-11-30 18:38:10',
  546. 'mytime' => '22:57:17'
  547. )),
  548. 'Child' => array(
  549. array(
  550. 'id' => 1,
  551. 'apple_id' => 2,
  552. 'color' => 'Red 1',
  553. 'name' => 'Red Apple 1',
  554. 'created' => '2006-11-22 10:38:58',
  555. 'date' => '1951-01-04',
  556. 'modified' => '2006-12-01 13:31:26',
  557. 'mytime' => '22:57:17',
  558. 'Parent' => array(
  559. 'id' => 2,
  560. 'apple_id' => 1,
  561. 'color' => 'Bright Red 1',
  562. 'name' => 'Bright Red Apple',
  563. 'created' => '2006-11-22 10:43:13',
  564. 'date' => '2014-01-01',
  565. 'modified' => '2006-11-30 18:38:10',
  566. 'mytime' => '22:57:17'
  567. ),
  568. 'Sample' => array(),
  569. 'Child' => array(
  570. array(
  571. 'id' => 2,
  572. 'apple_id' => 1,
  573. 'color' => 'Bright Red 1',
  574. 'name' => 'Bright Red Apple',
  575. 'created' => '2006-11-22 10:43:13',
  576. 'date' => '2014-01-01',
  577. 'modified' => '2006-11-30 18:38:10',
  578. 'mytime' => '22:57:17'
  579. ))),
  580. array(
  581. 'id' => 3,
  582. 'apple_id' => 2,
  583. 'color' => 'blue green',
  584. 'name' => 'green blue',
  585. 'created' => '2006-12-25 05:13:36',
  586. 'date' => '2006-12-25',
  587. 'modified' => '2006-12-25 05:23:24',
  588. 'mytime' => '22:57:17',
  589. 'Parent' => array(
  590. 'id' => 2,
  591. 'apple_id' => 1,
  592. 'color' => 'Bright Red 1',
  593. 'name' => 'Bright Red Apple',
  594. 'created' => '2006-11-22 10:43:13',
  595. 'date' => '2014-01-01',
  596. 'modified' => '2006-11-30 18:38:10',
  597. 'mytime' => '22:57:17'
  598. ),
  599. 'Sample' => array(
  600. 'id' => 1,
  601. 'apple_id' => 3,
  602. 'name' => 'sample1'
  603. )),
  604. array(
  605. 'id' => 4,
  606. 'apple_id' => 2,
  607. 'color' => 'Blue Green',
  608. 'name' => 'Test Name',
  609. 'created' => '2006-12-25 05:23:36',
  610. 'date' => '2006-12-25',
  611. 'modified' => '2006-12-25 05:23:36',
  612. 'mytime' => '22:57:17',
  613. 'Parent' => array(
  614. 'id' => 2,
  615. 'apple_id' => 1,
  616. 'color' => 'Bright Red 1',
  617. 'name' => 'Bright Red Apple',
  618. 'created' => '2006-11-22 10:43:13',
  619. 'date' => '2014-01-01',
  620. 'modified' => '2006-11-30 18:38:10',
  621. 'mytime' => '22:57:17'
  622. ),
  623. 'Sample' => array(
  624. 'id' => 3,
  625. 'apple_id' => 4,
  626. 'name' => 'sample3'
  627. ),
  628. 'Child' => array(
  629. array(
  630. 'id' => 6,
  631. 'apple_id' => 4,
  632. 'color' => 'My new appleOrange',
  633. 'name' => 'My new apple',
  634. 'created' => '2006-12-25 05:29:39',
  635. 'date' => '2006-12-25',
  636. 'modified' => '2006-12-25 05:29:39',
  637. 'mytime' => '22:57:17'
  638. ))))),
  639. array(
  640. 'Apple' => array(
  641. 'id' => 3,
  642. 'apple_id' => 2,
  643. 'color' => 'blue green',
  644. 'name' => 'green blue',
  645. 'created' => '2006-12-25 05:13:36',
  646. 'date' => '2006-12-25',
  647. 'modified' => '2006-12-25 05:23:24',
  648. 'mytime' => '22:57:17'
  649. ),
  650. 'Parent' => array(
  651. 'id' => 2,
  652. 'apple_id' => 1,
  653. 'color' => 'Bright Red 1',
  654. 'name' => 'Bright Red Apple',
  655. 'created' => '2006-11-22 10:43:13',
  656. 'date' => '2014-01-01',
  657. 'modified' => '2006-11-30 18:38:10',
  658. 'mytime' => '22:57:17',
  659. 'Parent' => array(
  660. 'id' => 1,
  661. 'apple_id' => 2,
  662. 'color' => 'Red 1',
  663. 'name' => 'Red Apple 1',
  664. 'created' => '2006-11-22 10:38:58',
  665. 'date' => '1951-01-04',
  666. 'modified' => '2006-12-01 13:31:26',
  667. 'mytime' => '22:57:17'
  668. ),
  669. 'Sample' => array(
  670. 'id' => 2,
  671. 'apple_id' => 2,
  672. 'name' => 'sample2'
  673. ),
  674. 'Child' => array(
  675. array(
  676. 'id' => 1,
  677. 'apple_id' => 2,
  678. 'color' => 'Red 1',
  679. 'name' => 'Red Apple 1',
  680. 'created' => '2006-11-22 10:38:58',
  681. 'date' => '1951-01-04',
  682. 'modified' => '2006-12-01 13:31:26',
  683. 'mytime' => '22:57:17'
  684. ),
  685. array(
  686. 'id' => 3,
  687. 'apple_id' => 2,
  688. 'color' => 'blue green',
  689. 'name' => 'green blue',
  690. 'created' => '2006-12-25 05:13:36',
  691. 'date' => '2006-12-25',
  692. 'modified' => '2006-12-25 05:23:24',
  693. 'mytime' => '22:57:17'
  694. ),
  695. array(
  696. 'id' => 4,
  697. 'apple_id' => 2,
  698. 'color' => 'Blue Green',
  699. 'name' => 'Test Name',
  700. 'created' => '2006-12-25 05:23:36',
  701. 'date' => '2006-12-25',
  702. 'modified' => '2006-12-25 05:23:36',
  703. 'mytime' => '22:57:17'
  704. ))),
  705. 'Sample' => array(
  706. 'id' => 1,
  707. 'apple_id' => 3,
  708. 'name' => 'sample1',
  709. 'Apple' => array(
  710. 'id' => 3,
  711. 'apple_id' => 2,
  712. 'color' => 'blue green',
  713. 'name' => 'green blue',
  714. 'created' => '2006-12-25 05:13:36',
  715. 'date' => '2006-12-25',
  716. 'modified' => '2006-12-25 05:23:24',
  717. 'mytime' => '22:57:17'
  718. )),
  719. 'Child' => array()
  720. ),
  721. array(
  722. 'Apple' => array(
  723. 'id' => 4,
  724. 'apple_id' => 2,
  725. 'color' => 'Blue Green',
  726. 'name' => 'Test Name',
  727. 'created' => '2006-12-25 05:23:36',
  728. 'date' => '2006-12-25',
  729. 'modified' => '2006-12-25 05:23:36',
  730. 'mytime' => '22:57:17'
  731. ),
  732. 'Parent' => array(
  733. 'id' => 2,
  734. 'apple_id' => 1,
  735. 'color' => 'Bright Red 1',
  736. 'name' => 'Bright Red Apple',
  737. 'created' => '2006-11-22 10:43:13',
  738. 'date' => '2014-01-01',
  739. 'modified' => '2006-11-30 18:38:10',
  740. 'mytime' => '22:57:17',
  741. 'Parent' => array(
  742. 'id' => 1,
  743. 'apple_id' => 2,
  744. 'color' => 'Red 1',
  745. 'name' => 'Red Apple 1',
  746. 'created' => '2006-11-22 10:38:58',
  747. 'date' => '1951-01-04',
  748. 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
  749. 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
  750. 'Child' => array(
  751. array(
  752. 'id' => 1,
  753. 'apple_id' => 2,
  754. 'color' => 'Red 1',
  755. 'name' => 'Red Apple 1',
  756. 'created' => '2006-11-22 10:38:58',
  757. 'date' => '1951-01-04',
  758. 'modified' => '2006-12-01 13:31:26',
  759. 'mytime' => '22:57:17'
  760. ),
  761. array(
  762. 'id' => 3,
  763. 'apple_id' => 2,
  764. 'color' => 'blue green',
  765. 'name' => 'green blue',
  766. 'created' => '2006-12-25 05:13:36',
  767. 'date' => '2006-12-25',
  768. 'modified' => '2006-12-25 05:23:24',
  769. 'mytime' => '22:57:17'
  770. ),
  771. array(
  772. 'id' => 4,
  773. 'apple_id' => 2,
  774. 'color' => 'Blue Green',
  775. 'name' => 'Test Name',
  776. 'created' => '2006-12-25 05:23:36',
  777. 'date' => '2006-12-25',
  778. 'modified' => '2006-12-25 05:23:36',
  779. 'mytime' => '22:57:17'
  780. ))),
  781. 'Sample' => array(
  782. 'id' => 3,
  783. 'apple_id' => 4,
  784. 'name' => 'sample3',
  785. 'Apple' => array(
  786. 'id' => 4,
  787. 'apple_id' => 2,
  788. 'color' => 'Blue Green',
  789. 'name' => 'Test Name',
  790. 'created' => '2006-12-25 05:23:36',
  791. 'date' => '2006-12-25',
  792. 'modified' => '2006-12-25 05:23:36',
  793. 'mytime' => '22:57:17'
  794. )),
  795. 'Child' => array(
  796. array(
  797. 'id' => 6,
  798. 'apple_id' => 4,
  799. 'color' => 'My new appleOrange',
  800. 'name' => 'My new apple',
  801. 'created' => '2006-12-25 05:29:39',
  802. 'date' => '2006-12-25',
  803. 'modified' => '2006-12-25 05:29:39',
  804. 'mytime' => '22:57:17',
  805. 'Parent' => array(
  806. 'id' => 4,
  807. 'apple_id' => 2,
  808. 'color' => 'Blue Green',
  809. 'name' => 'Test Name',
  810. 'created' => '2006-12-25 05:23:36',
  811. 'date' => '2006-12-25',
  812. 'modified' => '2006-12-25 05:23:36',
  813. 'mytime' => '22:57:17'
  814. ),
  815. 'Sample' => array(),
  816. 'Child' => array(
  817. array(
  818. 'id' => 7,
  819. 'apple_id' => 6,
  820. 'color' => 'Some wierd color',
  821. 'name' => 'Some odd color',
  822. 'created' => '2006-12-25 05:34:21',
  823. 'date' => '2006-12-25',
  824. 'modified' => '2006-12-25 05:34:21',
  825. 'mytime' => '22:57:17'
  826. ))))),
  827. array(
  828. 'Apple' => array(
  829. 'id' => 5,
  830. 'apple_id' => 5,
  831. 'color' => 'Green',
  832. 'name' => 'Blue Green',
  833. 'created' => '2006-12-25 05:24:06',
  834. 'date' => '2006-12-25',
  835. 'modified' => '2006-12-25 05:29:16',
  836. 'mytime' => '22:57:17'
  837. ),
  838. 'Parent' => array(
  839. 'id' => 5,
  840. 'apple_id' => 5,
  841. 'color' => 'Green',
  842. 'name' => 'Blue Green',
  843. 'created' => '2006-12-25 05:24:06',
  844. 'date' => '2006-12-25',
  845. 'modified' => '2006-12-25 05:29:16',
  846. 'mytime' => '22:57:17',
  847. 'Parent' => array(
  848. 'id' => 5,
  849. 'apple_id' => 5,
  850. 'color' => 'Green',
  851. 'name' => 'Blue Green',
  852. 'created' => '2006-12-25 05:24:06',
  853. 'date' => '2006-12-25',
  854. 'modified' => '2006-12-25 05:29:16',
  855. 'mytime' => '22:57:17'
  856. ),
  857. 'Sample' => array(
  858. 'id' => 4,
  859. 'apple_id' => 5,
  860. 'name' => 'sample4'
  861. ),
  862. 'Child' => array(
  863. array(
  864. 'id' => 5,
  865. 'apple_id' => 5,
  866. 'color' => 'Green',
  867. 'name' => 'Blue Green',
  868. 'created' => '2006-12-25 05:24:06',
  869. 'date' => '2006-12-25',
  870. 'modified' => '2006-12-25 05:29:16',
  871. 'mytime' => '22:57:17'
  872. ))),
  873. 'Sample' => array(
  874. 'id' => 4,
  875. 'apple_id' => 5,
  876. 'name' => 'sample4',
  877. 'Apple' => array(
  878. 'id' => 5,
  879. 'apple_id' => 5,
  880. 'color' => 'Green',
  881. 'name' => 'Blue Green',
  882. 'created' => '2006-12-25 05:24:06',
  883. 'date' => '2006-12-25',
  884. 'modified' => '2006-12-25 05:29:16',
  885. 'mytime' => '22:57:17'
  886. )),
  887. 'Child' => array(
  888. array(
  889. 'id' => 5,
  890. 'apple_id' => 5,
  891. 'color' => 'Green',
  892. 'name' => 'Blue Green',
  893. 'created' => '2006-12-25 05:24:06',
  894. 'date' => '2006-12-25',
  895. 'modified' => '2006-12-25 05:29:16',
  896. 'mytime' => '22:57:17',
  897. 'Parent' => array(
  898. 'id' => 5,
  899. 'apple_id' => 5,
  900. 'color' => 'Green',
  901. 'name' => 'Blue Green',
  902. 'created' => '2006-12-25 05:24:06',
  903. 'date' => '2006-12-25',
  904. 'modified' => '2006-12-25 05:29:16',
  905. 'mytime' => '22:57:17'
  906. ),
  907. 'Sample' => array(
  908. 'id' => 4,
  909. 'apple_id' => 5,
  910. 'name' => 'sample4'
  911. ),
  912. 'Child' => array(
  913. array(
  914. 'id' => 5,
  915. 'apple_id' => 5,
  916. 'color' => 'Green',
  917. 'name' => 'Blue Green',
  918. 'created' => '2006-12-25 05:24:06',
  919. 'date' => '2006-12-25',
  920. 'modified' => '2006-12-25 05:29:16',
  921. 'mytime' => '22:57:17'
  922. ))))),
  923. array(
  924. 'Apple' => array(
  925. 'id' => 6,
  926. 'apple_id' => 4,
  927. 'color' => 'My new appleOrange',
  928. 'name' => 'My new apple',
  929. 'created' => '2006-12-25 05:29:39',
  930. 'date' => '2006-12-25',
  931. 'modified' => '2006-12-25 05:29:39',
  932. 'mytime' => '22:57:17'
  933. ),
  934. 'Parent' => array(
  935. 'id' => 4,
  936. 'apple_id' => 2,
  937. 'color' => 'Blue Green',
  938. 'name' => 'Test Name',
  939. 'created' => '2006-12-25 05:23:36',
  940. 'date' => '2006-12-25',
  941. 'modified' => '2006-12-25 05:23:36',
  942. 'mytime' => '22:57:17',
  943. 'Parent' => array(
  944. 'id' => 2,
  945. 'apple_id' => 1,
  946. 'color' => 'Bright Red 1',
  947. 'name' => 'Bright Red Apple',
  948. 'created' => '2006-11-22 10:43:13',
  949. 'date' => '2014-01-01',
  950. 'modified' => '2006-11-30 18:38:10',
  951. 'mytime' => '22:57:17'
  952. ),
  953. 'Sample' => array(
  954. 'id' => 3,
  955. 'apple_id' => 4,
  956. 'name' => 'sample3'
  957. ),
  958. 'Child' => array(
  959. array(
  960. 'id' => 6,
  961. 'apple_id' => 4,
  962. 'color' => 'My new appleOrange',
  963. 'name' => 'My new apple',
  964. 'created' => '2006-12-25 05:29:39',
  965. 'date' => '2006-12-25',
  966. 'modified' => '2006-12-25 05:29:39',
  967. 'mytime' => '22:57:17'
  968. ))),
  969. 'Sample' => array(
  970. 'id' => '',
  971. 'apple_id' => '',
  972. 'name' => ''
  973. ),
  974. 'Child' => array(
  975. array(
  976. 'id' => 7,
  977. 'apple_id' => 6,
  978. 'color' => 'Some wierd color',
  979. 'name' => 'Some odd color',
  980. 'created' => '2006-12-25 05:34:21',
  981. 'date' => '2006-12-25',
  982. 'modified' => '2006-12-25 05:34:21',
  983. 'mytime' => '22:57:17',
  984. 'Parent' => array(
  985. 'id' => 6,
  986. 'apple_id' => 4,
  987. 'color' => 'My new appleOrange',
  988. 'name' => 'My new apple',
  989. 'created' => '2006-12-25 05:29:39',
  990. 'date' => '2006-12-25',
  991. 'modified' => '2006-12-25 05:29:39',
  992. 'mytime' => '22:57:17'
  993. ),
  994. 'Sample' => array()
  995. ))),
  996. array(
  997. 'Apple' => array(
  998. 'id' => 7,
  999. 'apple_id' => 6,
  1000. 'color' =>
  1001. 'Some wierd color',
  1002. 'name' => 'Some odd color',
  1003. 'created' => '2006-12-25 05:34:21',
  1004. 'date' => '2006-12-25',
  1005. 'modified' => '2006-12-25 05:34:21',
  1006. 'mytime' => '22:57:17'
  1007. ),
  1008. 'Parent' => array(
  1009. 'id' => 6,
  1010. 'apple_id' => 4,
  1011. 'color' => 'My new appleOrange',
  1012. 'name' => 'My new apple',
  1013. 'created' => '2006-12-25 05:29:39',
  1014. 'date' => '2006-12-25',
  1015. 'modified' => '2006-12-25 05:29:39',
  1016. 'mytime' => '22:57:17',
  1017. 'Parent' => array(
  1018. 'id' => 4,
  1019. 'apple_id' => 2,
  1020. 'color' => 'Blue Green',
  1021. 'name' => 'Test Name',
  1022. 'created' => '2006-12-25 05:23:36',
  1023. 'date' => '2006-12-25',
  1024. 'modified' => '2006-12-25 05:23:36',
  1025. 'mytime' => '22:57:17'
  1026. ),
  1027. 'Sample' => array(),
  1028. 'Child' => array(
  1029. array(
  1030. 'id' => 7,
  1031. 'apple_id' => 6,
  1032. 'color' => 'Some wierd color',
  1033. 'name' => 'Some odd color',
  1034. 'created' => '2006-12-25 05:34:21',
  1035. 'date' => '2006-12-25',
  1036. 'modified' => '2006-12-25 05:34:21',
  1037. 'mytime' => '22:57:17'
  1038. ))),
  1039. 'Sample' => array(
  1040. 'id' => '',
  1041. 'apple_id' => '',
  1042. 'name' => ''
  1043. ),
  1044. 'Child' => array()));
  1045. $this->assertEqual($result, $expected);
  1046. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1047. $this->assertTrue($result);
  1048. $result = $TestModel->find('all');
  1049. $expected = array(
  1050. array(
  1051. 'Apple' => array(
  1052. 'id' => 1,
  1053. 'apple_id' => 2,
  1054. 'color' => 'Red 1',
  1055. 'name' => 'Red Apple 1',
  1056. 'created' => '2006-11-22 10:38:58',
  1057. 'date' => '1951-01-04',
  1058. 'modified' => '2006-12-01 13:31:26',
  1059. 'mytime' => '22:57:17'),
  1060. 'Parent' => array(
  1061. 'id' => 2,
  1062. 'apple_id' => 1,
  1063. 'color' => 'Bright Red 1',
  1064. 'name' => 'Bright Red Apple',
  1065. 'created' => '2006-11-22 10:43:13',
  1066. 'date' => '2014-01-01',
  1067. 'modified' => '2006-11-30 18:38:10',
  1068. 'mytime' => '22:57:17',
  1069. 'Parent' => array(
  1070. 'id' => 1,
  1071. 'apple_id' => 2,
  1072. 'color' => 'Red 1',
  1073. 'name' => 'Red Apple 1',
  1074. 'created' => '2006-11-22 10:38:58',
  1075. 'date' => '1951-01-04',
  1076. 'modified' => '2006-12-01 13:31:26',
  1077. 'mytime' => '22:57:17'
  1078. ),
  1079. 'Child' => array(
  1080. array(
  1081. 'id' => 1,
  1082. 'apple_id' => 2,
  1083. 'color' => 'Red 1',
  1084. 'name' => 'Red Apple 1',
  1085. 'created' => '2006-11-22 10:38:58',
  1086. 'date' => '1951-01-04',
  1087. 'modified' => '2006-12-01 13:31:26',
  1088. 'mytime' => '22:57:17'
  1089. ),
  1090. array(
  1091. 'id' => 3,
  1092. 'apple_id' => 2,
  1093. 'color' => 'blue green',
  1094. 'name' => 'green blue',
  1095. 'created' => '2006-12-25 05:13:36',
  1096. 'date' => '2006-12-25',
  1097. 'modified' => '2006-12-25 05:23:24',
  1098. 'mytime' => '22:57:17'
  1099. ),
  1100. array(
  1101. 'id' => 4,
  1102. 'apple_id' => 2,
  1103. 'color' => 'Blue Green',
  1104. 'name' => 'Test Name',
  1105. 'created' => '2006-12-25 05:23:36',
  1106. 'date' => '2006-12-25',
  1107. 'modified' => '2006-12-25 05:23:36',
  1108. 'mytime' => '22:57:17'
  1109. ))),
  1110. 'Sample' => array(
  1111. 'id' =>'',
  1112. 'apple_id' => '',
  1113. 'name' => ''
  1114. ),
  1115. 'Child' => array(
  1116. array(
  1117. 'id' => 2,
  1118. 'apple_id' => 1,
  1119. 'color' => 'Bright Red 1',
  1120. 'name' => 'Bright Red Apple',
  1121. 'created' => '2006-11-22 10:43:13',
  1122. 'date' => '2014-01-01',
  1123. 'modified' => '2006-11-30 18:38:10',
  1124. 'mytime' => '22:57:17',
  1125. 'Parent' => array(
  1126. 'id' => 1,
  1127. 'apple_id' => 2,
  1128. 'color' => 'Red 1',
  1129. 'name' => 'Red Apple 1',
  1130. 'created' => '2006-11-22 10:38:58',
  1131. 'date' => '1951-01-04',
  1132. 'modified' => '2006-12-01 13:31:26',
  1133. 'mytime' => '22:57:17'
  1134. ),
  1135. 'Sample' => array(
  1136. 'id' => 2,
  1137. 'apple_id' => 2,
  1138. 'name' => 'sample2'
  1139. ),
  1140. 'Child' => array(
  1141. array(
  1142. 'id' => 1,
  1143. 'apple_id' => 2,
  1144. 'color' => 'Red 1',
  1145. 'name' => 'Red Apple 1',
  1146. 'created' => '2006-11-22 10:38:58',
  1147. 'date' => '1951-01-04',
  1148. 'modified' => '2006-12-01 13:31:26',
  1149. 'mytime' => '22:57:17'
  1150. ),
  1151. array(
  1152. 'id' => 3,
  1153. 'apple_id' => 2,
  1154. 'color' => 'blue green',
  1155. 'name' => 'green blue',
  1156. 'created' => '2006-12-25 05:13:36',
  1157. 'date' => '2006-12-25',
  1158. 'modified' => '2006-12-25 05:23:24',
  1159. 'mytime' => '22:57:17'
  1160. ),
  1161. array(
  1162. 'id' => 4,
  1163. 'apple_id' => 2,
  1164. 'color' => 'Blue Green',
  1165. 'name' => 'Test Name',
  1166. 'created' => '2006-12-25 05:23:36',
  1167. 'date' => '2006-12-25',
  1168. 'modified' => '2006-12-25 05:23:36',
  1169. 'mytime' => '22:57:17'
  1170. ))))),
  1171. array(
  1172. 'Apple' => array(
  1173. 'id' => 2,
  1174. 'apple_id' => 1,
  1175. 'color' => 'Bright Red 1',
  1176. 'name' => 'Bright Red Apple',
  1177. 'created' => '2006-11-22 10:43:13',
  1178. 'date' => '2014-01-01',
  1179. 'modified' => '2006-11-30 18:38:10',
  1180. 'mytime' => '22:57:17'
  1181. ),
  1182. 'Parent' => array(
  1183. 'id' => 1,
  1184. 'apple_id' => 2,
  1185. 'color' => 'Red 1',
  1186. 'name' => 'Red Apple 1',
  1187. 'created' => '2006-11-22 10:38:58',
  1188. 'date' => '1951-01-04',
  1189. 'modified' => '2006-12-01 13:31:26',
  1190. 'mytime' => '22:57:17',
  1191. 'Parent' => array(
  1192. 'id' => 2,
  1193. 'apple_id' => 1,
  1194. 'color' => 'Bright Red 1',
  1195. 'name' => 'Bright Red Apple',
  1196. 'created' => '2006-11-22 10:43:13',
  1197. 'date' => '2014-01-01',
  1198. 'modified' => '2006-11-30 18:38:10',
  1199. 'mytime' => '22:57:17'
  1200. ),
  1201. 'Child' => array(
  1202. array(
  1203. 'id' => 2,
  1204. 'apple_id' => 1,
  1205. 'color' => 'Bright Red 1',
  1206. 'name' => 'Bright Red Apple',
  1207. 'created' => '2006-11-22 10:43:13',
  1208. 'date' => '2014-01-01',
  1209. 'modified' => '2006-11-30 18:38:10',
  1210. 'mytime' => '22:57:17'
  1211. ))),
  1212. 'Sample' => array(
  1213. 'id' => 2,
  1214. 'apple_id' => 2,
  1215. 'name' => 'sample2',
  1216. 'Apple' => array(
  1217. 'id' => 2,
  1218. 'apple_id' => 1,
  1219. 'color' => 'Bright Red 1',
  1220. 'name' => 'Bright Red Apple',
  1221. 'created' => '2006-11-22 10:43:13',
  1222. 'date' => '2014-01-01',
  1223. 'modified' => '2006-11-30 18:38:10',
  1224. 'mytime' => '22:57:17'
  1225. )),
  1226. 'Child' => array(
  1227. array(
  1228. 'id' => 1,
  1229. 'apple_id' => 2,
  1230. 'color' => 'Red 1',
  1231. 'name' => 'Red Apple 1',
  1232. 'created' => '2006-11-22 10:38:58',
  1233. 'date' => '1951-01-04',
  1234. 'modified' => '2006-12-01 13:31:26',
  1235. 'mytime' => '22:57:17',
  1236. 'Parent' => array(
  1237. 'id' => 2,
  1238. 'apple_id' => 1,
  1239. 'color' => 'Bright Red 1',
  1240. 'name' => 'Bright Red Apple',
  1241. 'created' => '2006-11-22 10:43:13',
  1242. 'date' => '2014-01-01',
  1243. 'modified' => '2006-11-30 18:38:10',
  1244. 'mytime' => '22:57:17'
  1245. ),
  1246. 'Sample' => array(),
  1247. 'Child' => array(
  1248. array(
  1249. 'id' => 2,
  1250. 'apple_id' => 1,
  1251. 'color' => 'Bright Red 1',
  1252. 'name' => 'Bright Red Apple',
  1253. 'created' => '2006-11-22 10:43:13',
  1254. 'date' => '2014-01-01', 'modified' =>
  1255. '2006-11-30 18:38:10',
  1256. 'mytime' => '22:57:17'
  1257. ))),
  1258. array(
  1259. 'id' => 3,
  1260. 'apple_id' => 2,
  1261. 'color' => 'blue green',
  1262. 'name' => 'green blue',
  1263. 'created' => '2006-12-25 05:13:36',
  1264. 'date' => '2006-12-25',
  1265. 'modified' => '2006-12-25 05:23:24',
  1266. 'mytime' => '22:57:17',
  1267. 'Parent' => array(
  1268. 'id' => 2,
  1269. 'apple_id' => 1,
  1270. 'color' => 'Bright Red 1',
  1271. 'name' => 'Bright Red Apple',
  1272. 'created' => '2006-11-22 10:43:13',
  1273. 'date' => '2014-01-01',
  1274. 'modified' => '2006-11-30 18:38:10',
  1275. 'mytime' => '22:57:17'
  1276. ),
  1277. 'Sample' => array(
  1278. 'id' => 1,
  1279. 'apple_id' => 3,
  1280. 'name' => 'sample1'
  1281. )),
  1282. array(
  1283. 'id' => 4,
  1284. 'apple_id' => 2,
  1285. 'color' => 'Blue Green',
  1286. 'name' => 'Test Name',
  1287. 'created' => '2006-12-25 05:23:36',
  1288. 'date' => '2006-12-25',
  1289. 'modified' => '2006-12-25 05:23:36',
  1290. 'mytime' => '22:57:17',
  1291. 'Parent' => array(
  1292. 'id' => 2,
  1293. 'apple_id' => 1,
  1294. 'color' => 'Bright Red 1',
  1295. 'name' => 'Bright Red Apple',
  1296. 'created' => '2006-11-22 10:43:13',
  1297. 'date' => '2014-01-01',
  1298. 'modified' => '2006-11-30 18:38:10',
  1299. 'mytime' => '22:57:17'
  1300. ),
  1301. 'Sample' => array(
  1302. 'id' => 3,
  1303. 'apple_id' => 4,
  1304. 'name' => 'sample3'
  1305. ),
  1306. 'Child' => array(
  1307. array(
  1308. 'id' => 6,
  1309. 'apple_id' => 4,
  1310. 'color' => 'My new appleOrange',
  1311. 'name' => 'My new apple',
  1312. 'created' => '2006-12-25 05:29:39',
  1313. 'date' => '2006-12-25',
  1314. 'modified' => '2006-12-25 05:29:39',
  1315. 'mytime' => '22:57:17'
  1316. ))))),
  1317. array(
  1318. 'Apple' => array(
  1319. 'id' => 3,
  1320. 'apple_id' => 2,
  1321. 'color' => 'blue green',
  1322. 'name' => 'green blue',
  1323. 'created' => '2006-12-25 05:13:36',
  1324. 'date' => '2006-12-25',
  1325. 'modified' => '2006-12-25 05:23:24',
  1326. 'mytime' => '22:57:17'
  1327. ),
  1328. 'Parent' => array(
  1329. 'id' => 2,
  1330. 'apple_id' => 1,
  1331. 'color' => 'Bright Red 1',
  1332. 'name' => 'Bright Red Apple',
  1333. 'created' => '2006-11-22 10:43:13',
  1334. 'date' => '2014-01-01',
  1335. 'modified' => '2006-11-30 18:38:10',
  1336. 'mytime' => '22:57:17',
  1337. 'Parent' => array(
  1338. 'id' => 1,
  1339. 'apple_id' => 2,
  1340. 'color' => 'Red 1',
  1341. 'name' => 'Red Apple 1',
  1342. 'created' => '2006-11-22 10:38:58',
  1343. 'date' => '1951-01-04',
  1344. 'modified' => '2006-12-01 13:31:26',
  1345. 'mytime' => '22:57:17'
  1346. ),
  1347. 'Child' => array(
  1348. array(
  1349. 'id' => 1,
  1350. 'apple_id' => 2,
  1351. 'color' => 'Red 1',
  1352. 'name' => 'Red Apple 1',
  1353. 'created' => '2006-11-22 10:38:58',
  1354. 'date' => '1951-01-04',
  1355. 'modified' => '2006-12-01 13:31:26',
  1356. 'mytime' => '22:57:17'
  1357. ),
  1358. array(
  1359. 'id' => 3,
  1360. 'apple_id' => 2,
  1361. 'color' => 'blue green',
  1362. 'name' => 'green blue',
  1363. 'created' => '2006-12-25 05:13:36',
  1364. 'date' => '2006-12-25',
  1365. 'modified' => '2006-12-25 05:23:24',
  1366. 'mytime' => '22:57:17'
  1367. ),
  1368. array(
  1369. 'id' => 4,
  1370. 'apple_id' => 2,
  1371. 'color' => 'Blue Green',
  1372. 'name' => 'Test Name',
  1373. 'created' => '2006-12-25 05:23:36',
  1374. 'date' => '2006-12-25',
  1375. 'modified' => '2006-12-25 05:23:36',
  1376. 'mytime' => '22:57:17'
  1377. ))),
  1378. 'Sample' => array(
  1379. 'id' => 1,
  1380. 'apple_id' => 3,
  1381. 'name' => 'sample1',
  1382. 'Apple' => array(
  1383. 'id' => 3,
  1384. 'apple_id' => 2,
  1385. 'color' => 'blue green',
  1386. 'name' => 'green blue',
  1387. 'created' => '2006-12-25 05:13:36',
  1388. 'date' => '2006-12-25',
  1389. 'modified' => '2006-12-25 05:23:24',
  1390. 'mytime' => '22:57:17'
  1391. )),
  1392. 'Child' => array()
  1393. ),
  1394. array(
  1395. 'Apple' => array(
  1396. 'id' => 4,
  1397. 'apple_id' => 2,
  1398. 'color' => 'Blue Green',
  1399. 'name' => 'Test Name',
  1400. 'created' => '2006-12-25 05:23:36',
  1401. 'date' => '2006-12-25',
  1402. 'modified' => '2006-12-25 05:23:36',
  1403. 'mytime' => '22:57:17'
  1404. ),
  1405. 'Parent' => array(
  1406. 'id' => 2,
  1407. 'apple_id' => 1,
  1408. 'color' => 'Bright Red 1',
  1409. 'name' => 'Bright Red Apple',
  1410. 'created' => '2006-11-22 10:43:13',
  1411. 'date' => '2014-01-01',
  1412. 'modified' => '2006-11-30 18:38:10',
  1413. 'mytime' => '22:57:17',
  1414. 'Parent' => array(
  1415. 'id' => 1,
  1416. 'apple_id' => 2,
  1417. 'color' => 'Red 1',
  1418. 'name' => 'Red Apple 1',
  1419. 'created' => '2006-11-22 10:38:58',
  1420. 'date' => '1951-01-04',
  1421. 'modified' => '2006-12-01 13:31:26',
  1422. 'mytime' => '22:57:17'
  1423. ),
  1424. 'Child' => array(
  1425. array(
  1426. 'id' => 1,
  1427. 'apple_id' => 2,
  1428. 'color' => 'Red 1',
  1429. 'name' => 'Red Apple 1',
  1430. 'created' => '2006-11-22 10:38:58',
  1431. 'date' => '1951-01-04',
  1432. 'modified' => '2006-12-01 13:31:26',
  1433. 'mytime' => '22:57:17'
  1434. ),
  1435. array(
  1436. 'id' => 3,
  1437. 'apple_id' => 2,
  1438. 'color' => 'blue green',
  1439. 'name' => 'green blue',
  1440. 'created' => '2006-12-25 05:13:36',
  1441. 'date' => '2006-12-25',
  1442. 'modified' => '2006-12-25 05:23:24',
  1443. 'mytime' => '22:57:17'
  1444. ),
  1445. array(
  1446. 'id' => 4,
  1447. 'apple_id' => 2,
  1448. 'color' => 'Blue Green',
  1449. 'name' => 'Test Name',
  1450. 'created' => '2006-12-25 05:23:36',
  1451. 'date' => '2006-12-25',
  1452. 'modified' => '2006-12-25 05:23:36',
  1453. 'mytime' => '22:57:17'
  1454. ))),
  1455. 'Sample' => array(
  1456. 'id' => 3,
  1457. 'apple_id' => 4,
  1458. 'name' => 'sample3',
  1459. 'Apple' => array(
  1460. 'id' => 4,
  1461. 'apple_id' => 2,
  1462. 'color' => 'Blue Green',
  1463. 'name' => 'Test Name',
  1464. 'created' => '2006-12-25 05:23:36',
  1465. 'date' => '2006-12-25',
  1466. 'modified' => '2006-12-25 05:23:36',
  1467. 'mytime' => '22:57:17'
  1468. )),
  1469. 'Child' => array(
  1470. array(
  1471. 'id' => 6,
  1472. 'apple_id' => 4,
  1473. 'color' => 'My new appleOrange',
  1474. 'name' => 'My new apple',
  1475. 'created' => '2006-12-25 05:29:39',
  1476. 'date' => '2006-12-25',
  1477. 'modified' => '2006-12-25 05:29:39',
  1478. 'mytime' => '22:57:17',
  1479. 'Parent' => array(
  1480. 'id' => 4,
  1481. 'apple_id' => 2,
  1482. 'color' => 'Blue Green',
  1483. 'name' => 'Test Name',
  1484. 'created' => '2006-12-25 05:23:36',
  1485. 'date' => '2006-12-25',
  1486. 'modified' => '2006-12-25 05:23:36',
  1487. 'mytime' => '22:57:17'
  1488. ),
  1489. 'Sample' => array(),
  1490. 'Child' => array(
  1491. array(
  1492. 'id' => 7,
  1493. 'apple_id' => 6,
  1494. 'color' => 'Some wierd color',
  1495. 'name' => 'Some odd color',
  1496. 'created' => '2006-12-25 05:34:21',
  1497. 'date' => '2006-12-25',
  1498. 'modified' => '2006-12-25 05:34:21',
  1499. 'mytime' => '22:57:17'
  1500. ))))),
  1501. array(
  1502. 'Apple' => array(
  1503. 'id' => 5,
  1504. 'apple_id' => 5,
  1505. 'color' => 'Green',
  1506. 'name' => 'Blue Green',
  1507. 'created' => '2006-12-25 05:24:06',
  1508. 'date' => '2006-12-25',
  1509. 'modified' => '2006-12-25 05:29:16',
  1510. 'mytime' => '22:57:17'
  1511. ),
  1512. 'Parent' => array(
  1513. 'id' => 5,
  1514. 'apple_id' => 5,
  1515. 'color' => 'Green',
  1516. 'name' => 'Blue Green',
  1517. 'created' => '2006-12-25 05:24:06',
  1518. 'date' => '2006-12-25',
  1519. 'modified' => '2006-12-25 05:29:16',
  1520. 'mytime' => '22:57:17',
  1521. 'Parent' => array(
  1522. 'id' => 5,
  1523. 'apple_id' => 5,
  1524. 'color' => 'Green',
  1525. 'name' => 'Blue Green',
  1526. 'created' => '2006-12-25 05:24:06',
  1527. 'date' => '2006-12-25',
  1528. 'modified' => '2006-12-25 05:29:16',
  1529. 'mytime' => '22:57:17'
  1530. ),
  1531. 'Child' => array(
  1532. array(
  1533. 'id' => 5,
  1534. 'apple_id' => 5,
  1535. 'color' => 'Green',
  1536. 'name' => 'Blue Green',
  1537. 'created' => '2006-12-25 05:24:06',
  1538. 'date' => '2006-12-25',
  1539. 'modified' => '2006-12-25 05:29:16',
  1540. 'mytime' => '22:57:17'
  1541. ))),
  1542. 'Sample' => array(
  1543. 'id' => 4,
  1544. 'apple_id' => 5,
  1545. 'name' => 'sample4',
  1546. 'Apple' => array(
  1547. 'id' => 5,
  1548. 'apple_id' => 5,
  1549. 'color' => 'Green',
  1550. 'name' => 'Blue Green',
  1551. 'created' => '2006-12-25 05:24:06',
  1552. 'date' => '2006-12-25',
  1553. 'modified' => '2006-12-25 05:29:16',
  1554. 'mytime' => '22:57:17'
  1555. )),
  1556. 'Child' => array(
  1557. array(
  1558. 'id' => 5,
  1559. 'apple_id' => 5,
  1560. 'color' => 'Green',
  1561. 'name' => 'Blue Green',
  1562. 'created' => '2006-12-25 05:24:06',
  1563. 'date' => '2006-12-25',
  1564. 'modified' => '2006-12-25 05:29:16',
  1565. 'mytime' => '22:57:17',
  1566. 'Parent' => array(
  1567. 'id' => 5,
  1568. 'apple_id' => 5,
  1569. 'color' => 'Green',
  1570. 'name' => 'Blue Green',
  1571. 'created' => '2006-12-25 05:24:06',
  1572. 'date' => '2006-12-25',
  1573. 'modified' => '2006-12-25 05:29:16',
  1574. 'mytime' => '22:57:17'
  1575. ),
  1576. 'Sample' => array(
  1577. 'id' => 4,
  1578. 'apple_id' => 5,
  1579. 'name' => 'sample4'
  1580. ),
  1581. 'Child' => array(
  1582. array(
  1583. 'id' => 5,
  1584. 'apple_id' => 5,
  1585. 'color' => 'Green',
  1586. 'name' => 'Blue Green',
  1587. 'created' => '2006-12-25 05:24:06',
  1588. 'date' => '2006-12-25',
  1589. 'modified' => '2006-12-25 05:29:16',
  1590. 'mytime' => '22:57:17'
  1591. ))))),
  1592. array(
  1593. 'Apple' => array(
  1594. 'id' => 6,
  1595. 'apple_id' => 4,
  1596. 'color' => 'My new appleOrange',
  1597. 'name' => 'My new apple',
  1598. 'created' => '2006-12-25 05:29:39',
  1599. 'date' => '2006-12-25',
  1600. 'modified' => '2006-12-25 05:29:39',
  1601. 'mytime' => '22:57:17'
  1602. ),
  1603. 'Parent' => array(
  1604. 'id' => 4,
  1605. 'apple_id' => 2,
  1606. 'color' => 'Blue Green',
  1607. 'name' => 'Test Name',
  1608. 'created' => '2006-12-25 05:23:36',
  1609. 'date' => '2006-12-25',
  1610. 'modified' => '2006-12-25 05:23:36',
  1611. 'mytime' => '22:57:17',
  1612. 'Parent' => array(
  1613. 'id' => 2,
  1614. 'apple_id' => 1,
  1615. 'color' => 'Bright Red 1',
  1616. 'name' => 'Bright Red Apple',
  1617. 'created' => '2006-11-22 10:43:13',
  1618. 'date' => '2014-01-01',
  1619. 'modified' => '2006-11-30 18:38:10',
  1620. 'mytime' => '22:57:17'
  1621. ),
  1622. 'Child' => array(
  1623. array(
  1624. 'id' => 6,
  1625. 'apple_id' => 4,
  1626. 'color' => 'My new appleOrange',
  1627. 'name' => 'My new apple',
  1628. 'created' => '2006-12-25 05:29:39',
  1629. 'date' => '2006-12-25',
  1630. 'modified' => '2006-12-25 05:29:39',
  1631. 'mytime' => '22:57:17'
  1632. ))),
  1633. 'Sample' => array(
  1634. 'id' => '',
  1635. 'apple_id' => '',
  1636. 'name' => ''
  1637. ),
  1638. 'Child' => array(
  1639. array(
  1640. 'id' => 7,
  1641. 'apple_id' => 6,
  1642. 'color' => 'Some wierd color',
  1643. 'name' => 'Some odd color',
  1644. 'created' => '2006-12-25 05:34:21',
  1645. 'date' => '2006-12-25',
  1646. 'modified' => '2006-12-25 05:34:21',
  1647. 'mytime' => '22:57:17',
  1648. 'Parent' => array(
  1649. 'id' => 6,
  1650. 'apple_id' => 4,
  1651. 'color' => 'My new appleOrange',
  1652. 'name' => 'My new apple',
  1653. 'created' => '2006-12-25 05:29:39',
  1654. 'date' => '2006-12-25',
  1655. 'modified' => '2006-12-25 05:29:39',
  1656. 'mytime' => '22:57:17'
  1657. ),
  1658. 'Sample' => array()
  1659. ))),
  1660. array(
  1661. 'Apple' => array(
  1662. 'id' => 7,
  1663. 'apple_id' => 6,
  1664. 'color' => 'Some wierd color',
  1665. 'name' => 'Some odd color',
  1666. 'created' => '2006-12-25 05:34:21',
  1667. 'date' => '2006-12-25',
  1668. 'modified' => '2006-12-25 05:34:21',
  1669. 'mytime' => '22:57:17'
  1670. ),
  1671. 'Parent' => array(
  1672. 'id' => 6,
  1673. 'apple_id' => 4,
  1674. 'color' => 'My new appleOrange',
  1675. 'name' => 'My new apple',
  1676. 'created' => '2006-12-25 05:29:39',
  1677. 'date' => '2006-12-25',
  1678. 'modified' => '2006-12-25 05:29:39',
  1679. 'mytime' => '22:57:17',
  1680. 'Parent' => array(
  1681. 'id' => 4,
  1682. 'apple_id' => 2,
  1683. 'color' => 'Blue Green',
  1684. 'name' => 'Test Name',
  1685. 'created' => '2006-12-25 05:23:36',
  1686. 'date' => '2006-12-25',
  1687. 'modified' => '2006-12-25 05:23:36',
  1688. 'mytime' => '22:57:17'
  1689. ),
  1690. 'Child' => array(
  1691. array(
  1692. 'id' => 7,
  1693. 'apple_id' => 6,
  1694. 'color' => 'Some wierd color',
  1695. 'name' => 'Some odd color',
  1696. 'created' => '2006-12-25 05:34:21',
  1697. 'date' => '2006-12-25',
  1698. 'modified' => '2006-12-25 05:34:21',
  1699. 'mytime' => '22:57:17'
  1700. ))),
  1701. 'Sample' => array(
  1702. 'id' => '',
  1703. 'apple_id' => '',
  1704. 'name' => ''
  1705. ),
  1706. 'Child' => array()
  1707. ));
  1708. $this->assertEqual($result, $expected);
  1709. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1710. $this->assertTrue($result);
  1711. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  1712. $this->assertTrue($result);
  1713. $result = $TestModel->find('all');
  1714. $expected = array(
  1715. array(
  1716. 'Apple' => array (
  1717. 'id' => 1,
  1718. 'apple_id' => 2,
  1719. 'color' => 'Red 1',
  1720. 'name' => 'Red Apple 1',
  1721. 'created' => '2006-11-22 10:38:58',
  1722. 'date' => '1951-01-04',
  1723. 'modified' => '2006-12-01 13:31:26',
  1724. 'mytime' => '22:57:17'
  1725. ),
  1726. 'Parent' => array(
  1727. 'id' => 2,
  1728. 'apple_id' => 1,
  1729. 'color' => 'Bright Red 1',
  1730. 'name' => 'Bright Red Apple',
  1731. 'created' => '2006-11-22 10:43:13',
  1732. 'date' => '2014-01-01',
  1733. 'modified' => '2006-11-30 18:38:10',
  1734. 'mytime' => '22:57:17',
  1735. 'Parent' => array(
  1736. 'id' => 1,

Large files files are truncated, but you can click here to view the full file