File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ class MY_Model extends CI_Model
31
31
* This model's default primary key or unique identifier.
32
32
* Used by the get(), update() and delete() functions.
33
33
*/
34
- protected $ primary_key = ' id ' ;
34
+ protected $ primary_key = NULL ;
35
35
36
36
/**
37
37
* Support for soft deletes and this model's 'deleted' key
@@ -104,6 +104,7 @@ public function __construct()
104
104
$ this ->load ->helper ('inflector ' );
105
105
106
106
$ this ->_fetch_table ();
107
+ $ this ->_fetch_primary_key ();
107
108
$ this ->_database = $ this ->db ;
108
109
109
110
array_unshift ($ this ->before_create , 'protect_attributes ' );
@@ -859,6 +860,17 @@ private function _fetch_table()
859
860
}
860
861
}
861
862
863
+ /**
864
+ * Guess the primary key for current table
865
+ */
866
+ private function _fetch_primary_key ()
867
+ {
868
+ if ($ this ->primary_key == NULl )
869
+ {
870
+ $ this ->primary_key = $ this ->_database ->query ("SHOW KEYS FROM ` " .$ this ->_table ."` WHERE Key_name = 'PRIMARY' " )->row ()->Column_name ;
871
+ }
872
+ }
873
+
862
874
/**
863
875
* Set WHERE parameters, cleverly
864
876
*/
You can’t perform that action at this time.
0 commit comments