Code Duplication    Length = 23-23 lines in 2 locations

system/Inji/Model.php 2 locations

@@ 944-966 (lines=23) @@
941
            $query->distinct = $options['distinct'];
942
        }
943
944
        foreach (static::$needJoin as $rel) {
945
            $relations = static::relations();
946
            foreach ($query->join as $item) {
947
                if ($item[0] === $relations[$rel]['model']::table() && $item[3] === '') {
948
                    continue 2;
949
                }
950
            }
951
            if (isset($relations[$rel])) {
952
                $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type'];
953
                switch ($type) {
954
                    case 'to':
955
                        $relCol = $relations[$rel]['col'];
956
                        static::fixPrefix($relCol);
957
                        $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol);
958
                        break;
959
                    case 'one':
960
                        $col = $relations[$rel]['col'];
961
                        $relations[$rel]['model']::fixPrefix($col);
962
                        $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col);
963
                        break;
964
                }
965
            }
966
        }
967
        static::$needJoin = [];
968
969
        foreach (static::$relJoins as $join) {
@@ 1297-1319 (lines=23) @@
1294
            $query->limit($start, $limit);
1295
        }
1296
1297
        foreach (static::$needJoin as $rel) {
1298
            $relations = static::relations();
1299
            foreach ($query->join as $item) {
1300
                if ($item[0] === $relations[$rel]['model']::table() && $item[3] === '') {
1301
                    continue 2;
1302
                }
1303
            }
1304
            if (isset($relations[$rel])) {
1305
                $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type'];
1306
                switch ($type) {
1307
                    case 'to':
1308
                        $relCol = $relations[$rel]['col'];
1309
                        static::fixPrefix($relCol);
1310
                        $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol);
1311
                        break;
1312
                    case 'one':
1313
                        $col = $relations[$rel]['col'];
1314
                        $relations[$rel]['model']::fixPrefix($col);
1315
                        $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col);
1316
                        break;
1317
                }
1318
            }
1319
        }
1320
        static::$needJoin = [];
1321
        foreach (static::$relJoins as $join) {
1322
            foreach ($query->join as $item) {