| @@ 991-1013 (lines=23) @@ | ||
| 988 | $query->distinct = $options['distinct']; |
|
| 989 | } |
|
| 990 | ||
| 991 | foreach (static::$needJoin as $rel) { |
|
| 992 | $relations = static::relations(); |
|
| 993 | foreach ($query->join as $item) { |
|
| 994 | if ($item[0] === $relations[$rel]['model']::table() && $item[3] === '') { |
|
| 995 | continue 2; |
|
| 996 | } |
|
| 997 | } |
|
| 998 | if (isset($relations[$rel])) { |
|
| 999 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
|
| 1000 | switch ($type) { |
|
| 1001 | case 'to': |
|
| 1002 | $relCol = $relations[$rel]['col']; |
|
| 1003 | static::fixPrefix($relCol); |
|
| 1004 | $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
|
| 1005 | break; |
|
| 1006 | case 'one': |
|
| 1007 | $col = $relations[$rel]['col']; |
|
| 1008 | $relations[$rel]['model']::fixPrefix($col); |
|
| 1009 | $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
|
| 1010 | break; |
|
| 1011 | } |
|
| 1012 | } |
|
| 1013 | } |
|
| 1014 | static::$needJoin = []; |
|
| 1015 | ||
| 1016 | foreach (static::$relJoins as $join) { |
|
| @@ 1150-1172 (lines=23) @@ | ||
| 1147 | $query->limit($start, $limit); |
|
| 1148 | } |
|
| 1149 | ||
| 1150 | foreach (static::$needJoin as $rel) { |
|
| 1151 | $relations = static::relations(); |
|
| 1152 | foreach ($query->join as $item) { |
|
| 1153 | if ($item[0] === $relations[$rel]['model']::table() && $item[3] === '') { |
|
| 1154 | continue 2; |
|
| 1155 | } |
|
| 1156 | } |
|
| 1157 | if (isset($relations[$rel])) { |
|
| 1158 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
|
| 1159 | switch ($type) { |
|
| 1160 | case 'to': |
|
| 1161 | $relCol = $relations[$rel]['col']; |
|
| 1162 | static::fixPrefix($relCol); |
|
| 1163 | $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
|
| 1164 | break; |
|
| 1165 | case 'one': |
|
| 1166 | $col = $relations[$rel]['col']; |
|
| 1167 | $relations[$rel]['model']::fixPrefix($col); |
|
| 1168 | $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
|
| 1169 | break; |
|
| 1170 | } |
|
| 1171 | } |
|
| 1172 | } |
|
| 1173 | static::$needJoin = []; |
|
| 1174 | foreach (static::$relJoins as $join) { |
|
| 1175 | foreach ($query->join as $item) { |
|