File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public static function set_db($db) {
109
109
110
110
return self ::_error ('db is not valid ' );
111
111
}
112
-
112
+
113
113
/**
114
114
* Get the DB object from the base Model
115
115
*
@@ -125,10 +125,19 @@ public static function get_db() {
125
125
* @return bool
126
126
* Returns true if table exists and successfully registered to the Model class. Otherwise false.
127
127
*/
128
- public static function register ($ table , $ pk = 'id ' ) {
129
- if ($ table_info = self ::$ db ->get_table_info ($ table )) {
128
+ public static function register ($ table , $ pk = null ) {
129
+ if ($ fields = self ::$ db ->get_table_info ($ table )) {
130
+ if (!$ pk ) {
131
+ foreach ($ fields as $ field => $ info ) {
132
+ if ($ info ['primary ' ] === true ) {
133
+ $ pk = $ field ;
134
+ break ;
135
+ }
136
+ }
137
+ }
138
+
130
139
self ::$ _models [self ::get_name ()] = [
131
- 'fields ' => self :: $ db -> get_table_info ( $ table ) ,
140
+ 'fields ' => $ fields ,
132
141
'table ' => $ table ,
133
142
'pk ' => $ pk
134
143
];
You can’t perform that action at this time.
0 commit comments