@@ -103,9 +103,9 @@ public static function where($field, $value, $objects = true) {
103
103
}
104
104
105
105
public static function whereR ($ attr , $ field , $ value , $ tableR ) {
106
- self ::setTableForStaticCall ();
106
+ self ::setTableForStaticCall ($ tableR );
107
107
self ::getConnection ();
108
- $ sql = "SELECT " . $ attr . " FROM " . $ tableR . " WHERE " . $ field . " = : " . $ field ;
108
+ $ sql = "SELECT " . $ attr . " FROM " . static :: $ table . " WHERE " . $ field . " = : " . $ field ;
109
109
//print_r($sql);
110
110
$ results = self ::$ db ->select ($ sql , array (": " . $ field => $ value ));
111
111
@@ -129,6 +129,15 @@ public static function advancedWhere($condition, $values) {
129
129
return $ results ;
130
130
}
131
131
132
+ public static function getIn ($ field ,$ range ) {
133
+ self ::setTableForStaticCall ();
134
+ self ::getConnection ();
135
+ $ sql = "SELECT * FROM " . static ::$ table . " WHERE " . $ field . " IN( " .$ range .") " ;
136
+ $ results = self ::$ db ->select ($ sql );
137
+
138
+ return $ results ;
139
+ }
140
+
132
141
public static function getById ($ id ,$ objects = true ) {
133
142
self ::setTableForStaticCall ();
134
143
$ self = self ::where ("id " , $ id , $ objects );
@@ -365,12 +374,26 @@ public function has($rType,$rName){
365
374
return $ r ;
366
375
}
367
376
377
+ public function belongsTM ($ rName ){
378
+
379
+ $ rule = $ this ->getBelongsToMany ()[$ rName ];
380
+ $ r = self ::whereR ("* " , $ rule ['join_as ' ],
381
+ $ this ->{"get " . ucfirst ($ rule ["my_key " ])}(),
382
+ $ rule ["join_table " ]);
383
+ return $ r ;
384
+ }
385
+
368
386
/******************************************+*******************************
369
387
** OBJECT POPULATION
370
388
*************************************************************************/
371
389
372
390
public function populate ($ rType ,$ rName ){
373
- $ objs = $ this ->has ($ rType , $ rName );
391
+
392
+ if ($ rType == "belongsToMany " ){
393
+ $ objs = $ this ->belongsTM ($ rName );
394
+ }else {
395
+ $ objs = $ this ->has ($ rType , $ rName );
396
+ }
374
397
$ this ->{lcfirst ($ rName )} = $ objs ;
375
398
}
376
399
0 commit comments