@@ -363,6 +363,39 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
363
363
);
364
364
}
365
365
366
+ /**
367
+ * NonConventionalPrimaryKeyFixture class
368
+ *
369
+ * @package Cake.Test.Case.Model
370
+ */
371
+ class NonConventionalPrimaryKeyFixture extends CakeTestFixture {
372
+
373
+ /**
374
+ * name property
375
+ *
376
+ * @var string
377
+ */
378
+ public $ name = 'NonConventional ' ;
379
+
380
+ /**
381
+ * table property
382
+ *
383
+ * @var string
384
+ */
385
+ public $ table = 'non_conventional ' ;
386
+
387
+ /**
388
+ * fields property
389
+ *
390
+ * @var array
391
+ */
392
+ public $ fields = array (
393
+ 'version_id ' => array ('type ' => 'integer ' , 'key ' => 'primary ' ),
394
+ 'id ' => array ('type ' => 'integer ' ),
395
+ 'name ' => 'string '
396
+ );
397
+ }
398
+
366
399
/**
367
400
* SchemaPrefixAuthUser class
368
401
*
@@ -649,6 +682,36 @@ public function testSchemaReadWithCrossDatabase() {
649
682
$ fixture ->drop ($ db );
650
683
}
651
684
685
+ /**
686
+ * testSchemaRead method when a primary key is on a non-conventional column
687
+ *
688
+ * @return void
689
+ */
690
+ public function testSchemaReadWithNonConventionalPrimaryKey () {
691
+ $ db = ConnectionManager::getDataSource ('test ' );
692
+ $ fixture = new NonConventionalPrimaryKeyFixture ();
693
+ $ fixture ->create ($ db );
694
+
695
+ $ read = $ this ->Schema ->read (array (
696
+ 'connection ' => 'test ' ,
697
+ 'name ' => 'TestApp ' ,
698
+ 'models ' => false
699
+ ));
700
+ $ fixture ->drop ($ db );
701
+
702
+ $ has_table = isset ($ read ['tables ' ]['non_conventional ' ]);
703
+ $ this ->assertTrue ($ has_table , 'non_conventional table should appear ' );
704
+ if ($ has_table ) {
705
+ $ version_id_has_key = isset ($ read ['tables ' ]['non_conventional ' ]['version_id ' ]['key ' ]);
706
+ $ this ->assertTrue ($ version_id_has_key , 'version_id key should be set ' );
707
+ if ($ version_id_has_key ) {
708
+ $ version_id_key_is_primary = $ read ['tables ' ]['non_conventional ' ]['version_id ' ]['key ' ] === 'primary ' ;
709
+ $ this ->assertTrue ($ version_id_key_is_primary , 'version_id key should be primary ' );
710
+ }
711
+ $ this ->assertFalse (isset ($ read ['tables ' ]['non_conventional ' ]['id ' ]['key ' ]), 'id key should not be set ' );
712
+ }
713
+ }
714
+
652
715
/**
653
716
* test that tables are generated correctly
654
717
*
0 commit comments