TestCommon.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Db_Table_TestSetup
  24. */
  25. require_once 'Zend/Db/Table/TestSetup.php';
  26. /**
  27. * @see Zend_Loader
  28. */
  29. require_once 'Zend/Loader.php';
  30. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  31. /**
  32. * @category Zend
  33. * @package Zend_Db
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. abstract class Zend_Db_Table_Relationships_TestCommon extends Zend_Db_Table_TestSetup
  39. {
  40. public function testTableRelationshipFindParentRow()
  41. {
  42. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  43. $account_name = $this->_db->foldCase('account_name');
  44. $table = $this->_table['bugs'];
  45. $childRows = $table->fetchAll("$bug_id = 1");
  46. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  47. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  48. $childRow1 = $childRows->current();
  49. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  50. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  51. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts');
  52. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  53. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  54. $this->assertEquals('goofy', $parentRow->$account_name);
  55. }
  56. public function testTableRelationshipFindParentRowSelect()
  57. {
  58. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  59. $account_name = $this->_db->foldCase('account_name');
  60. $account_name_column = $this->_db->quoteIdentifier('account_name', true);
  61. $table = $this->_table['bugs'];
  62. $select = $table->select()->where($account_name_column . ' = ?', 'goofy');
  63. $childRows = $table->fetchAll("$bug_id = 1");
  64. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  65. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  66. $childRow1 = $childRows->current();
  67. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  68. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  69. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts', null, $select);
  70. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  71. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  72. $this->assertEquals('goofy', $parentRow->$account_name);
  73. }
  74. public function testTableRelationshipMagicFindParentRow()
  75. {
  76. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  77. $account_name = $this->_db->foldCase('account_name');
  78. $table = $this->_table['bugs'];
  79. $childRows = $table->fetchAll("$bug_id = 1");
  80. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  81. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  82. $childRow1 = $childRows->current();
  83. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  84. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  85. $parentRow = $childRow1->findParentMy_ZendDbTable_TableAccounts();
  86. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  87. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  88. $this->assertEquals('goofy', $parentRow->$account_name);
  89. }
  90. public function testTableRelationshipMagicFindParentRowSelect()
  91. {
  92. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  93. $account_name = $this->_db->foldCase('account_name');
  94. $account_name_column = $this->_db->quoteIdentifier('account_name', true);
  95. $table = $this->_table['bugs'];
  96. $select = $table->select()->where($account_name_column . ' = ?', 'goofy');
  97. $childRows = $table->fetchAll("$bug_id = 1");
  98. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  99. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  100. $childRow1 = $childRows->current();
  101. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  102. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  103. $parentRow = $childRow1->findParentMy_ZendDbTable_TableAccounts($select);
  104. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  105. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  106. $this->assertEquals('goofy', $parentRow->$account_name);
  107. }
  108. public function testTableRelationshipMagicException()
  109. {
  110. $table = $this->_table['bugs'];
  111. $parentRows = $table->find(1);
  112. $parentRow1 = $parentRows->current();
  113. // Completely bogus method
  114. try {
  115. $result = $parentRow1->nonExistantMethod();
  116. $this->fail('Expected to catch Zend_Db_Table_Row_Exception');
  117. } catch (Zend_Exception $e) {
  118. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  119. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  120. $this->assertEquals("Unrecognized method 'nonExistantMethod()'", $e->getMessage());
  121. }
  122. }
  123. public function testTableRelationshipFindParentRowException()
  124. {
  125. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  126. $table = $this->_table['bugs'];
  127. $childRows = $table->fetchAll("$bug_id = 1");
  128. $childRow1 = $childRows->current();
  129. try {
  130. $parentRow = $childRow1->findParentRow('nonexistant_class');
  131. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  132. } catch (Zend_Exception $e) {
  133. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  134. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  135. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  136. }
  137. try {
  138. $parentRow = $childRow1->findParentRow(new stdClass());
  139. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for wrong table class');
  140. } catch (Zend_Exception $e) {
  141. $this->assertType('Zend_Db_Table_Exception', $e,
  142. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  143. $this->assertEquals('Parent table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  144. }
  145. }
  146. public function testTableRelationshipFindManyToManyRowset()
  147. {
  148. $table = $this->_table['bugs'];
  149. $originRows = $table->find(1);
  150. $originRow1 = $originRows->current();
  151. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts');
  152. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  153. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  154. $this->assertEquals(3, $destRows->count());
  155. }
  156. public function testTableRelationshipFindManyToManyRowsetSelect()
  157. {
  158. $product_name = $this->_db->foldCase('product_name');
  159. $bug_id = $this->_db->foldCase('bug_id');
  160. $bug_id_column = $this->_db->quoteIdentifier('bug_id', true);
  161. $table = $this->_table['bugs'];
  162. $select = $table->select()->where($bug_id_column . ' = ?', 1)
  163. ->limit(2)
  164. ->order($product_name . ' ASC');
  165. $originRows = $table->find(1);
  166. $originRow1 = $originRows->current();
  167. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts',
  168. null, null, $select);
  169. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  170. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  171. $this->assertEquals(2, $destRows->count());
  172. $childRow = $destRows->current();
  173. $this->assertEquals('Linux', $childRow->$product_name);
  174. }
  175. public function testTableRelationshipMagicFindManyToManyRowset()
  176. {
  177. $table = $this->_table['bugs'];
  178. $originRows = $table->find(1);
  179. $originRow1 = $originRows->current();
  180. $destRows = $originRow1->findMy_ZendDbTable_TableProductsViaMy_ZendDbTable_TableBugsProducts();
  181. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  182. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  183. $this->assertEquals(3, $destRows->count());
  184. }
  185. public function testTableRelationshipMagicFindManyToManyRowsetSelect()
  186. {
  187. $product_name = $this->_db->foldCase('product_name');
  188. $bug_id = $this->_db->foldCase('bug_id');
  189. $bug_id_column = $this->_db->quoteIdentifier('bug_id', true);
  190. $table = $this->_table['bugs'];
  191. $select = $table->select()->where($bug_id_column . ' = ?', 1)
  192. ->limit(2)
  193. ->order($product_name . ' ASC');
  194. $originRows = $table->find(1);
  195. $originRow1 = $originRows->current();
  196. $destRows = $originRow1->findMy_ZendDbTable_TableProductsViaMy_ZendDbTable_TableBugsProducts($select);
  197. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  198. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  199. $this->assertEquals(2, $destRows->count());
  200. $childRow = $destRows->current();
  201. $this->assertEquals('Linux', $childRow->$product_name);
  202. }
  203. public function testTableRelationshipFindManyToManyRowsetException()
  204. {
  205. $table = $this->_table['bugs'];
  206. $originRows = $table->find(1);
  207. $originRow1 = $originRows->current();
  208. // Use nonexistant class for destination table
  209. try {
  210. $destRows = $originRow1->findManyToManyRowset('nonexistant_class', 'My_ZendDbTable_TableBugsProducts');
  211. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  212. } catch (Zend_Exception $e) {
  213. $this->assertType('Zend_Db_Table_Exception', $e,
  214. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  215. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  216. }
  217. // Use stdClass instead of table class for destination table
  218. try {
  219. $destRows = $originRow1->findManyToManyRowset(new stdClass(), 'My_ZendDbTable_TableBugsProducts');
  220. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  221. } catch (Zend_Exception $e) {
  222. $this->assertType('Zend_Db_Table_Exception', $e,
  223. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  224. $this->assertEquals('Match table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  225. }
  226. // Use nonexistant class for intersection table
  227. try {
  228. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'nonexistant_class');
  229. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  230. } catch (Zend_Exception $e) {
  231. $this->assertType('Zend_Db_Table_Exception', $e,
  232. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  233. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  234. }
  235. // Use stdClass instead of table class for intersection table
  236. try {
  237. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', new stdClass());
  238. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  239. } catch (Zend_Exception $e) {
  240. $this->assertType('Zend_Db_Table_Exception', $e,
  241. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  242. $this->assertEquals('Intersection table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  243. }
  244. }
  245. public function testTableRelationshipFindDependentRowset()
  246. {
  247. $table = $this->_table['bugs'];
  248. $bug_id = $this->_db->foldCase('bug_id');
  249. $product_id = $this->_db->foldCase('product_id');
  250. $parentRows = $table->find(1);
  251. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  252. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  253. $parentRow1 = $parentRows->current();
  254. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugsProducts');
  255. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  256. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  257. $this->assertEquals(3, $childRows->count());
  258. $childRow1 = $childRows->current();
  259. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  260. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  261. $this->assertEquals(1, $childRow1->$bug_id);
  262. $this->assertEquals(1, $childRow1->$product_id);
  263. }
  264. public function testTableRelationshipFindDependentRowsetSelect()
  265. {
  266. $table = $this->_table['bugs'];
  267. $bug_id = $this->_db->foldCase('bug_id');
  268. $product_id = $this->_db->foldCase('product_id');
  269. $select = $table->select()->limit(2)
  270. ->order($product_id . ' DESC');
  271. $parentRows = $table->find(1);
  272. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  273. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  274. $parentRow1 = $parentRows->current();
  275. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugsProducts', null, $select);
  276. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  277. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  278. $childRow1 = $childRows->current();
  279. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  280. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  281. $this->assertEquals(1, $childRow1->$bug_id);
  282. $this->assertEquals(3, $childRow1->$product_id);
  283. }
  284. public function testTableRelationshipMagicFindDependentRowset()
  285. {
  286. $table = $this->_table['bugs'];
  287. $bug_id = $this->_db->foldCase('bug_id');
  288. $product_id = $this->_db->foldCase('product_id');
  289. $parentRows = $table->find(1);
  290. $parentRow1 = $parentRows->current();
  291. $childRows = $parentRow1->findMy_ZendDbTable_TableBugsProducts();
  292. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  293. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  294. $this->assertEquals(3, $childRows->count());
  295. $childRow1 = $childRows->current();
  296. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  297. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  298. $this->assertEquals(1, $childRow1->$bug_id);
  299. $this->assertEquals(1, $childRow1->$product_id);
  300. }
  301. public function testTableRelationshipMagicFindDependentRowsetSelect()
  302. {
  303. $table = $this->_table['bugs'];
  304. $bug_id = $this->_db->foldCase('bug_id');
  305. $product_id = $this->_db->foldCase('product_id');
  306. $select = $table->select()->limit(2)
  307. ->order($product_id . ' DESC');
  308. $parentRows = $table->find(1);
  309. $parentRow1 = $parentRows->current();
  310. $childRows = $parentRow1->findMy_ZendDbTable_TableBugsProducts($select);
  311. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  312. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  313. $this->assertEquals(2, $childRows->count());
  314. $childRow1 = $childRows->current();
  315. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  316. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  317. $this->assertEquals(1, $childRow1->$bug_id);
  318. $this->assertEquals(3, $childRow1->$product_id);
  319. }
  320. public function testTableRelationshipFindDependentRowsetException()
  321. {
  322. $table = $this->_table['bugs'];
  323. $parentRows = $table->find(1);
  324. $parentRow1 = $parentRows->current();
  325. try {
  326. $childRows = $parentRow1->findDependentRowset('nonexistant_class');
  327. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  328. } catch (Zend_Exception $e) {
  329. $this->assertType('Zend_Db_Table_Exception', $e,
  330. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  331. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  332. }
  333. try {
  334. $childRows = $parentRow1->findDependentRowset(new stdClass());
  335. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for wrong table class');
  336. } catch (Zend_Exception $e) {
  337. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  338. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  339. $this->assertEquals('Dependent table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  340. }
  341. }
  342. /**
  343. * Ensures that basic cascading update functionality succeeds using strings for single columns
  344. *
  345. * @return void
  346. */
  347. public function testTableRelationshipCascadingUpdateUsageBasicString()
  348. {
  349. $bug = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  350. ->find(1)
  351. ->current();
  352. $bug_id = $this->_db->foldCase('bug_id');
  353. $this->assertEquals(
  354. 3,
  355. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  356. 'Expecting to find three dependent rows'
  357. );
  358. $bug->$bug_id = 333;
  359. $bug->save();
  360. $this->assertEquals(
  361. 3,
  362. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  363. 'Expecting to find three dependent rows'
  364. );
  365. foreach ($bugProducts as $bugProduct) {
  366. $this->assertEquals(333, $bugProduct->$bug_id);
  367. }
  368. $bug->$bug_id = 1;
  369. $bug->save();
  370. $this->assertEquals(
  371. 3,
  372. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  373. 'Expecting to find three dependent rows'
  374. );
  375. foreach ($bugProducts as $bugProduct) {
  376. $this->assertEquals(1, $bugProduct->$bug_id);
  377. }
  378. }
  379. /**
  380. * Ensures that basic cascading update functionality succeeds using arrays for single columns
  381. *
  382. * @return void
  383. */
  384. public function testTableRelationshipCascadingUpdateUsageBasicArray()
  385. {
  386. $account1 = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  387. ->find('mmouse')
  388. ->current();
  389. $account_name = $this->_db->foldCase('account_name');
  390. $reported_by = $this->_db->foldCase('reported_by');
  391. $this->assertEquals(
  392. 1,
  393. count($account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  394. 'Expecting to find one dependent row'
  395. );
  396. $account1->$account_name = 'daisy';
  397. $account1->save();
  398. $this->assertEquals(
  399. 1,
  400. count($account1Bugs = $account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  401. 'Expecting to find one dependent row'
  402. );
  403. foreach ($account1Bugs as $account1Bug) {
  404. $this->assertEquals('daisy', $account1Bug->$reported_by);
  405. }
  406. $account1->$account_name = 'mmouse';
  407. $account1->save();
  408. $this->assertEquals(
  409. 1,
  410. count($account1Bugs = $account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  411. 'Expecting to find one dependent row'
  412. );
  413. foreach ($account1Bugs as $account1Bug) {
  414. $this->assertEquals('mmouse', $account1Bug->$reported_by);
  415. }
  416. }
  417. /**
  418. * Ensures that cascading update functionality is not run when onUpdate != self::CASCADE
  419. *
  420. * @return void
  421. */
  422. public function testTableRelationshipCascadingUpdateUsageInvalidNoop()
  423. {
  424. $product1 = $this->_getTable('My_ZendDbTable_TableProductsCustom')
  425. ->find(1)
  426. ->current();
  427. $this->assertEquals(
  428. 1,
  429. count($product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  430. 'Expecting to find one dependent row'
  431. );
  432. $product_id = $this->_db->foldCase('product_id');
  433. $product1->$product_id = 333;
  434. $product1->save();
  435. $this->assertEquals(
  436. 0,
  437. count($product1BugsProducts = $product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  438. 'Expecting to find one dependent row'
  439. );
  440. $product1->$product_id = 1;
  441. $product1->save();
  442. $this->assertEquals(
  443. 1,
  444. count($product1BugsProducts = $product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  445. 'Expecting to find one dependent row'
  446. );
  447. foreach ($product1BugsProducts as $product1BugsProduct) {
  448. $this->assertEquals(1, $product1BugsProduct->$product_id);
  449. }
  450. }
  451. /**
  452. * Ensures that basic cascading delete functionality succeeds using strings for single columns
  453. *
  454. * @return void
  455. */
  456. public function testTableRelationshipCascadingDeleteUsageBasicString()
  457. {
  458. $bug1 = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  459. ->find(1)
  460. ->current();
  461. $this->assertEquals(
  462. 3,
  463. count($bug1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  464. 'Expecting to find three dependent rows'
  465. );
  466. $bug1->delete();
  467. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  468. $this->assertEquals(
  469. 0,
  470. count($this->_getTable('My_ZendDbTable_TableBugsProductsCustom')->fetchAll("$bug_id = 1")),
  471. 'Expecting cascading delete to have reduced dependent rows to zero'
  472. );
  473. }
  474. /**
  475. * Ensures that basic cascading delete functionality succeeds using arrays for single columns
  476. *
  477. * @return void
  478. */
  479. public function testTableRelationshipCascadingDeleteUsageBasicArray()
  480. {
  481. $reported_by = $this->_db->quoteIdentifier('reported_by', true);
  482. $account1 = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  483. ->find('mmouse')
  484. ->current();
  485. $this->assertEquals(
  486. 1,
  487. count($account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  488. 'Expecting to find one dependent row'
  489. );
  490. $account1->delete();
  491. $tableBugsCustom = $this->_getTable('My_ZendDbTable_TableBugsCustom');
  492. $this->assertEquals(
  493. 0,
  494. count(
  495. $tableBugsCustom->fetchAll(
  496. $tableBugsCustom->getAdapter()
  497. ->quoteInto("$reported_by = ?", 'mmouse')
  498. )
  499. ),
  500. 'Expecting cascading delete to have reduced dependent rows to zero'
  501. );
  502. }
  503. /**
  504. * Ensures that cascading delete functionality is not run when onDelete != self::CASCADE
  505. *
  506. * @return void
  507. */
  508. public function testTableRelationshipCascadingDeleteUsageInvalidNoop()
  509. {
  510. $product1 = $this->_getTable('My_ZendDbTable_TableProductsCustom')
  511. ->find(1)
  512. ->current();
  513. $this->assertEquals(
  514. 1,
  515. count($product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  516. 'Expecting to find one dependent row'
  517. );
  518. $product1->delete();
  519. $product_id = $this->_db->quoteIdentifier('product_id', true);
  520. $this->assertEquals(
  521. 1,
  522. count($this->_getTable('My_ZendDbTable_TableBugsProductsCustom')->fetchAll("$product_id = 1")),
  523. 'Expecting to find one dependent row'
  524. );
  525. }
  526. public function testTableRelationshipGetReference()
  527. {
  528. $table = $this->_table['bugs'];
  529. $map = $table->getReference('My_ZendDbTable_TableAccounts', 'Reporter');
  530. $this->assertThat($map, $this->arrayHasKey('columns'));
  531. $this->assertThat($map, $this->arrayHasKey('refTableClass'));
  532. $this->assertThat($map, $this->arrayHasKey('refColumns'));
  533. }
  534. public function testTableRelationshipGetReferenceException()
  535. {
  536. $table = $this->_table['bugs'];
  537. try {
  538. $table->getReference('My_ZendDbTable_TableAccounts', 'Nonexistent');
  539. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent reference rule');
  540. } catch (Zend_Exception $e) {
  541. $this->assertType('Zend_Db_Table_Exception', $e,
  542. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  543. }
  544. try {
  545. $table->getReference('Nonexistent', 'Reporter');
  546. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent rule tableClass');
  547. } catch (Zend_Exception $e) {
  548. $this->assertType('Zend_Db_Table_Exception', $e,
  549. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  550. }
  551. try {
  552. $table->getReference('Nonexistent');
  553. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent rule tableClass');
  554. } catch (Zend_Exception $e) {
  555. $this->assertType('Zend_Db_Table_Exception', $e,
  556. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  557. }
  558. }
  559. /**
  560. * Ensures that findParentRow() returns an instance of a custom row class when passed an instance
  561. * of the table class having $_rowClass overridden.
  562. *
  563. * @return void
  564. */
  565. public function testTableRelationshipFindParentRowCustomInstance()
  566. {
  567. $this->_useMyIncludePath();
  568. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  569. Zend_Loader::loadClass($myRowClass);
  570. $bug1Reporter = $this->_table['bugs']
  571. ->find(1)
  572. ->current()
  573. ->findParentRow($this->_table['accounts']->setRowClass($myRowClass));
  574. $this->assertType($myRowClass, $bug1Reporter,
  575. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  576. }
  577. /**
  578. * Ensures that findParentRow() returns an instance of a custom row class when passed a string class
  579. * name, where the class has $_rowClass overridden.
  580. *
  581. * @return void
  582. */
  583. public function testTableRelationshipFindParentRowCustomClass()
  584. {
  585. $this->_useMyIncludePath();
  586. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  587. Zend_Loader::loadClass($myRowClass);
  588. Zend_Loader::loadClass('My_ZendDbTable_TableAccountsCustom');
  589. $bug1Reporter = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  590. ->find(1)
  591. ->current()
  592. ->findParentRow(new My_ZendDbTable_TableAccountsCustom(array('db' => $this->_db)));
  593. $this->assertType($myRowClass, $bug1Reporter,
  594. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  595. }
  596. /**
  597. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  598. * passed an instance of the table class.
  599. *
  600. * @return void
  601. */
  602. public function testTableRelationshipFindDependentRowsetCustomInstance()
  603. {
  604. $this->_useMyIncludePath();
  605. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  606. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  607. Zend_Loader::loadClass($myRowsetClass);
  608. $account_name = $this->_db->quoteIdentifier('account_name', true);
  609. $bugs = $this->_table['accounts']
  610. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  611. ->findDependentRowset(
  612. $this->_table['bugs']
  613. ->setRowsetClass($myRowsetClass)
  614. ->setRowClass($myRowClass),
  615. 'Engineer'
  616. );
  617. $this->assertType($myRowsetClass, $bugs,
  618. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  619. $this->assertEquals(3, count($bugs));
  620. foreach ($bugs as $bug) {
  621. $this->assertType($myRowClass, $bug,
  622. "Expecting object of type $myRowClass, got ".get_class($bug));
  623. }
  624. }
  625. /**
  626. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  627. * passed the named class.
  628. *
  629. * @return void
  630. */
  631. public function testTableRelationshipFindDependentRowsetCustomClass()
  632. {
  633. $this->_useMyIncludePath();
  634. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  635. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  636. Zend_Loader::loadClass($myRowsetClass);
  637. $account_name = $this->_db->quoteIdentifier('account_name', true);
  638. $bugs = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  639. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  640. ->findDependentRowset('My_ZendDbTable_TableBugsCustom', 'Engineer');
  641. $this->assertType($myRowsetClass, $bugs,
  642. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  643. $this->assertEquals(3, count($bugs));
  644. foreach ($bugs as $bug) {
  645. $this->assertType($myRowClass, $bug,
  646. "Expecting object of type $myRowClass, got ".get_class($bug));
  647. }
  648. }
  649. /**
  650. * Ensures that findManyToManyRowset() returns instances of custom row and rowset class when
  651. * passed an instance of the table class.
  652. *
  653. * @return void
  654. */
  655. public function testTableRelationshipFindManyToManyRowsetCustomInstance()
  656. {
  657. $this->_useMyIncludePath();
  658. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  659. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  660. Zend_Loader::loadClass($myRowsetClass);
  661. $bug1Products = $this->_table['bugs']
  662. ->find(1)
  663. ->current()
  664. ->findManyToManyRowset(
  665. $this->_table['products']
  666. ->setRowsetClass($myRowsetClass)
  667. ->setRowClass($myRowClass),
  668. 'My_ZendDbTable_TableBugsProducts'
  669. );
  670. $this->assertType($myRowsetClass, $bug1Products,
  671. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  672. $this->assertEquals(3, count($bug1Products));
  673. foreach ($bug1Products as $bug1Product) {
  674. $this->assertType($myRowClass, $bug1Product,
  675. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  676. }
  677. }
  678. /**
  679. * Ensures that findManyToManyRowset() returns instances of custom row and rowset classes when
  680. * passed the named class.
  681. *
  682. * @return void
  683. */
  684. public function testTableRelationshipFindManyToManyRowsetCustomClass()
  685. {
  686. $this->_useMyIncludePath();
  687. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  688. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  689. Zend_Loader::loadClass($myRowsetClass);
  690. $bug1Products = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  691. ->find(1)
  692. ->current()
  693. ->findManyToManyRowset(
  694. 'My_ZendDbTable_TableProductsCustom',
  695. 'My_ZendDbTable_TableBugsProductsCustom'
  696. );
  697. $this->assertType($myRowsetClass, $bug1Products,
  698. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  699. $this->assertEquals(3, count($bug1Products));
  700. foreach ($bug1Products as $bug1Product) {
  701. $this->assertType($myRowClass, $bug1Product,
  702. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  703. }
  704. }
  705. /**
  706. * Ensures that rows returned by findParentRow() are updatable.
  707. *
  708. * @return void
  709. */
  710. public function testTableRelationshipFindParentRowIsUpdateable()
  711. {
  712. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  713. $account_name = $this->_db->foldCase('account_name');
  714. $table = $this->_table['bugs'];
  715. $childRows = $table->fetchAll("$bug_id = 1");
  716. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  717. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  718. $childRow1 = $childRows->current();
  719. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  720. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  721. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts');
  722. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  723. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  724. $this->assertEquals('goofy', $parentRow->$account_name);
  725. $parentRow->$account_name = 'clarabell';
  726. try {
  727. $parentRow->save();
  728. } catch (Zend_Exception $e) {
  729. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  730. }
  731. $accounts = $this->_db->quoteIdentifier('zfaccounts', true);
  732. $account_name = $this->_db->quoteIdentifier('account_name', true);
  733. $accounts_list = $this->_db->fetchCol("SELECT $account_name from $accounts ORDER BY $account_name");
  734. // if the save() did an UPDATE instead of an INSERT, then goofy should
  735. // be missing, and clarabell should be present
  736. $this->assertEquals(array('clarabell', 'dduck', 'mmouse'), $accounts_list);
  737. }
  738. /**
  739. * Ensures that rows returned by findDependentRowset() are updatable.
  740. *
  741. * @return void
  742. */
  743. public function testTableRelationshipFindDependentRowsetIsUpdateable()
  744. {
  745. $table = $this->_table['accounts'];
  746. $bug_id_column = $this->_db->foldCase('bug_id');
  747. $bug_description = $this->_db->foldCase('bug_description');
  748. $parentRows = $table->find('mmouse');
  749. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  750. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  751. $parentRow1 = $parentRows->current();
  752. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugs');
  753. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  754. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  755. $this->assertEquals(1, $childRows->count());
  756. $childRow1 = $childRows->current();
  757. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  758. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  759. $childRow1->$bug_description = 'Updated description';
  760. $bug_id = $childRow1->$bug_id_column;
  761. try {
  762. $childRow1->save();
  763. } catch (Zend_Exception $e) {
  764. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  765. }
  766. // find the row we just updated and make sure it has the new value.
  767. $bugs_table = $this->_table['bugs'];
  768. $bugs_rows = $bugs_table->find($bug_id);
  769. $this->assertEquals(1, $bugs_rows->count());
  770. $bug1 = $bugs_rows->current();
  771. $this->assertEquals($bug_id, $bug1->$bug_id_column);
  772. $this->assertEquals('Updated description', $bug1->$bug_description);
  773. }
  774. /**
  775. * Ensures that rows returned by findManyToManyRowset() are updatable.
  776. *
  777. * @return void
  778. */
  779. public function testTableRelationshipFindManyToManyRowsetIsUpdateable()
  780. {
  781. $table = $this->_table['bugs'];
  782. $product_id_column = $this->_db->foldCase('product_id');
  783. $product_name = $this->_db->foldCase('product_name');
  784. $originRows = $table->find(1);
  785. $originRow1 = $originRows->current();
  786. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts');
  787. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  788. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  789. $this->assertEquals(3, $destRows->count());
  790. $row1 = $destRows->current();
  791. $product_id = $row1->$product_id_column;
  792. $row1->$product_name = 'AmigaOS';
  793. try {
  794. $row1->save();
  795. } catch (Zend_Exception $e) {
  796. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  797. }
  798. // find the row we just updated and make sure it has the new value.
  799. $products_table = $this->_table['products'];
  800. $product_rows = $products_table->find($product_id);
  801. $this->assertEquals(1, $product_rows->count());
  802. $product_row = $product_rows->current();
  803. $this->assertEquals($product_id, $product_row->$product_id_column);
  804. $this->assertEquals('AmigaOS', $product_row->$product_name);
  805. }
  806. public function testTableRelationshipOmitRefColumns()
  807. {
  808. $refMap = array(
  809. 'Reporter' => array(
  810. 'columns' => array('reported_by'),
  811. 'refTableClass' => 'My_ZendDbTable_TableAccounts'
  812. )
  813. );
  814. $table = $this->_getTable('My_ZendDbTable_TableSpecial',
  815. array(
  816. 'name' => 'zfbugs',
  817. 'referenceMap' => $refMap
  818. )
  819. );
  820. $bug1 = $table->find(1)->current();
  821. $reporter = $bug1->findParentRow('My_ZendDbTable_TableAccounts');
  822. $this->assertEquals(array('account_name' => 'goofy'), $reporter->toArray());
  823. }
  824. /**
  825. * Test that findParentRow() works even if the column names are
  826. * not the same.
  827. */
  828. public function testTableRelationshipFindParentRowWithDissimilarColumns()
  829. {
  830. $bug_id = $this->_db->foldCase('bug_id');
  831. $product_id = $this->_db->foldCase('product_id');
  832. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  833. $intRow = $intersectionTable->find(2, 3)->current();
  834. $bugRow = $intRow->findParentRow('My_ZendDbTable_TableBugs');
  835. $this->assertEquals(2, $bugRow->$bug_id);
  836. $productRow = $intRow->findParentRow('My_ZendDbTable_TableProducts');
  837. $this->assertEquals(3, $productRow->$product_id);
  838. }
  839. /**
  840. * Test that findDependentRowset() works even if the column names are
  841. * not the same.
  842. */
  843. public function testTableRelationshipFindDependentRowsetWithDissimilarColumns()
  844. {
  845. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  846. $bugsTable = $this->_getTable('My_ZendDbTable_TableBugs');
  847. $bugRow = $bugsTable->find(2)->current();
  848. $intRows = $bugRow->findDependentRowset($intersectionTable);
  849. $this->assertEquals(array(2, 3), array_values($intRows->current()->toArray()));
  850. }
  851. /**
  852. * Test that findManyToManyRowset() works even if the column names are
  853. * not the same.
  854. */
  855. public function testTableRelationshipFindManyToManyRowsetWithDissimilarColumns()
  856. {
  857. $product_id = $this->_db->foldCase('product_id');
  858. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  859. $bugsTable = $this->_getTable('My_ZendDbTable_TableBugs');
  860. $bugRow = $bugsTable->find(2)->current();
  861. $productRows = $bugRow->findManyToManyRowset('My_ZendDbTable_TableProducts', $intersectionTable);
  862. $this->assertEquals(3, $productRows->current()->$product_id);
  863. }
  864. /**
  865. * Test that findManyToManyRowset() works even if the column types are
  866. * not the same.
  867. */
  868. public function testTableRelationshipFindManyToManyRowsetWithDissimilarTypes()
  869. {
  870. $table = $this->_table['products'];
  871. $originRows = $table->find(1);
  872. $originRow1 = $originRows->current();
  873. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableBugs', 'My_ZendDbTable_TableBugsProducts');
  874. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  875. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  876. $this->assertEquals(1, $destRows->count());
  877. }
  878. /**
  879. * Utility Methods Below
  880. *
  881. */
  882. /**
  883. * Create database table based on BUGS_PRODUCTS bug with alternative
  884. * spellings of column names. Then create a Table class for this
  885. * physical table and return it.
  886. */
  887. protected function _getBugsProductsWithDissimilarColumns()
  888. {
  889. $altCols = array(
  890. 'boog_id' => 'INTEGER NOT NULL',
  891. 'produck_id' => 'INTEGER NOT NULL',
  892. 'PRIMARY KEY' => 'boog_id,produck_id'
  893. );
  894. $this->_util->createTable('AltBugsProducts', $altCols);
  895. $altBugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfalt_bugs_products'), true);
  896. $bugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfbugs_products'), true);
  897. $this->_db->query("INSERT INTO $altBugsProducts SELECT * FROM $bugsProducts");
  898. $refMap = array(
  899. 'Boog' => array(
  900. 'columns' => array('boog_id'),
  901. 'refTableClass' => 'My_ZendDbTable_TableBugs',
  902. 'refColumns' => array('bug_id')
  903. ),
  904. 'Produck' => array(
  905. 'columns' => array('produck_id'),
  906. 'refTableClass' => 'My_ZendDbTable_TableProducts',
  907. 'refColumns' => array('product_id')
  908. )
  909. );
  910. $options = array('name' => 'zfalt_bugs_products', 'referenceMap' => $refMap);
  911. $table = $this->_getTable('My_ZendDbTable_TableSpecial', $options);
  912. return $table;
  913. }
  914. }