(s)
| 1021 | This is useful when constructing queries with relations to other tables. |
| 1022 | """ |
| 1023 | def _format(s): |
| 1024 | if not "." in s: |
| 1025 | # Field could be wrapped in a function: year(date) => year(table.date). |
| 1026 | p = s.endswith(")") and re.match(r"^("+sql_functions+r")\(", s, re.I) or None |
| 1027 | i = p and len(p.group(0)) or 0 |
| 1028 | return "%s%s.%s" % (s[:i], table, s[i:]) |
| 1029 | return s |
| 1030 | if isinstance(field, (list, tuple)): |
| 1031 | return [_format(f) for f in field] |
| 1032 | return _format(field) |