Changeset 315
- Timestamp:
- 08/20/07 19:39:43 (1 year ago)
- Files:
-
- trunk/lib/AkActiveRecord.php (modified) (2 diffs)
- trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php (modified) (1 diff)
- trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php (modified) (1 diff)
- trunk/lib/AkActiveRecord/AkHasMany.php (modified) (2 diffs)
- trunk/test/fixtures/app/installers/comment_installer.php (added)
- trunk/test/fixtures/app/models/comment.php (added)
- trunk/test/fixtures/app/models/post.php (modified) (1 diff)
- trunk/test/unit/lib/AkActiveRecord/AkHasMany.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkActiveRecord.php
r312 r315 2674 2674 } 2675 2675 2676 return $this->_columns;2676 return (array)$this->_columns; 2677 2677 } 2678 2678 … … 2705 2705 trigger_error(Ak::t('Ooops! Could not fetch details for the table %table_name.', array('%table_name'=>$this->getTableName())), E_USER_ERROR); 2706 2706 return false; 2707 }elseif(is_array($column_objects)){ 2707 }elseif (empty($column_objects)){ 2708 $this->_runCurrentModelInstallerIfExists($column_objects); 2709 } 2710 if(is_array($column_objects)){ 2708 2711 foreach (array_keys($column_objects) as $k){ 2709 2712 $this->setColumnSettings($column_objects[$k]->name, $column_objects[$k]); trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php
r285 r315 419 419 $objects[$i]->$association_id->_newRecord = false; 420 420 } 421 422 /**423 * @todo FIXME This is a dirty hack for sqlite table joins which are not exclusive as they are on MySql424 * this makes table joins behave the same way as they do on MySql425 */426 }elseif (in_array($association_id, $included_associations) && $this->_getDatabaseType() == 'sqlite'){427 $false = false;428 return $false;429 421 } 430 422 } trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php
r285 r315 762 762 if(empty($ModelInstance)){ 763 763 $class_name = $this->getOption($this->association_id, 'class_name'); 764 Ak::import($class_name); 764 765 $ModelInstance =& new $class_name(); 765 766 } trunk/lib/AkActiveRecord/AkHasMany.php
r285 r315 566 566 $finder_options['selection'] = trim($finder_options['selection'], ', '); 567 567 568 /** 569 * @todo Refactorize me. This is too confusing 570 */ 571 $finder_options['conditions'] = 572 // If owner is not available we build the searcher without an specific id 573 (empty($owner_id) ? '' : 574 575 // We have an Id so we add it to the conditions 576 ' '.$Associated->_addTableAliasesToAssociatedSql('_'.$this->association_id, $options['foreign_key']).' = '.$owner_id.' '. 577 // After adding the Id we need to add AND in case we have a previous contidion available 578 (!empty($options['conditions']) ? ' AND ' : ' ')). 579 580 // We add previous conditions 581 (!empty($options['conditions']) ? 582 $Associated->_addTableAliasesToAssociatedSql('_'.$this->association_id, $options['conditions']).' ' : ''); 583 568 $finder_options['conditions'] = empty($options['conditions']) ? '' : 569 570 $Associated->_addTableAliasesToAssociatedSql('_'.$this->association_id, $options['conditions']).' '; 571 584 572 return $finder_options; 585 573 } … … 615 603 if(empty($ModelInstance)){ 616 604 $class_name = $this->getOption($this->association_id, 'class_name'); 605 Ak::import($class_name); 617 606 $ModelInstance =& new $class_name(); 618 607 } trunk/test/fixtures/app/models/post.php
r313 r315 3 3 class Post extends ActiveRecord 4 4 { 5 var $has_many = 'comments'; 5 6 } 6 7 trunk/test/unit/lib/AkActiveRecord/AkHasMany.php
r217 r315 9 9 10 10 11 class test_AkActiveRecord_hasMany_Associations extends UnitTestCase11 class test_AkActiveRecord_hasMany_Associations extends AkUnitTest 12 12 { 13 13 … … 57 57 $this->assertNull($Property->pictures[0]->get('property_id')); 58 58 59 //$Property->dbug();60 59 $MountainViews =& new Picture(array('title'=>'Mountain views')); 61 60 $this->assertTrue($MountainViews->isNewRecord()); … … 133 132 $this->assertIdentical($Property->picture->count(), 0); 134 133 135 $this->assertFalse($Property->find('first', array('include'=>'pictures'))); 136 134 //$this->assertTrue($Property =& $Property->find('first', array('include'=>'pictures'))); 135 //$this->assertIdentical($Property->picture->count(), 0); 136 137 137 $Picture =& new Picture(); 138 138 $Alicia =& $Picture->create(array('title'=>'Alicia')); … … 213 213 $this->assertEqual($VillaAltea->pictures[0]->get('title'), 'Garden'); 214 214 } 215 215 216 216 /**/ 217 217 … … 220 220 $Property =& new Property(array('description'=>'Ruins in Matamon')); 221 221 $this->assertTrue($Property->save()); 222 222 223 223 $South =& $Property->picture->create(array('title'=>'South views')); 224 224 $this->assertReference($South, $Property->pictures[0]); 225 225 $this->assertFalse($South->isNewRecord()); 226 226 227 227 $pic_id = $South->getId(); 228 228 229 229 $Property =& new Property($Property->getId()); 230 230 $this->assertTrue($Property->destroy()); 231 231 232 232 $Picture =& new Picture(); 233 233 234 234 $this->assertFalse($Picture->find($pic_id)); 235 236 } 237 235 236 } 237 238 function _test_should_not_die_on_unincluded_model() 239 { 240 $this->installAndIncludeModels(array('Post')); 241 $Post =& new Post(); 242 $Post->dbug(); 243 $Post->find('all', array('include' => array('comments'))); 244 } 245 246 function test_should_find_owner_even_if_it_has_no_relations() 247 { 248 $this->installAndIncludeModels(array('Post', 'Comment')); 249 250 $Post =& new Post(array('title' => 'Post for unit testing', 'body' => 'This is a post for testing the model')); 251 252 $Post->save(); 253 $Post->reload(); 254 255 $expected_id = $Post->getId(); 256 257 $this->assertTrue($Result =& $Post->find($expected_id, array('include' => array('comments')))); 258 $this->assertEqual($Result->getId(), $expected_id); 259 } 260 261 function test_should_find_owner_using_related_conditions() 262 { 263 $this->installAndIncludeModels(array('Post', 'Comment')); 264 265 $Post =& new Post(array('title' => 'Post for unit testing', 'body' => 'This is a post for testing the model')); 266 $Post->comment->create(array('body' => 'hello', 'name' => 'Aditya')); 267 $Post->save(); 268 $Post->reload(); 269 270 $expected_id = $Post->getId(); 271 272 $this->assertTrue($Result =& $Post->find($expected_id, array('include' => array('comments'), 'conditions' => "name = 'Aditya'"))); 273 274 $this->assertEqual($Result->comments[0]->get('name'), 'Aditya'); 275 } 238 276 } 239 277
