Defines a relation between two tables in the database. When executing a table query, fields from the linked table will also be available (to disambiguate between field names, use table.field_name).
(self, table1, field1, table2, field2, join="left")
| 636 | remove = drop |
| 637 | |
| 638 | def link(self, table1, field1, table2, field2, join="left"): |
| 639 | """ Defines a relation between two tables in the database. |
| 640 | When executing a table query, fields from the linked table will also be available |
| 641 | (to disambiguate between field names, use table.field_name). |
| 642 | """ |
| 643 | if isinstance(table1, Table): |
| 644 | table1 = table1.name |
| 645 | if isinstance(table2, Table): |
| 646 | table2 = table2.name |
| 647 | self.relations.append((table1, field1, table2, field2, join)) |
| 648 | |
| 649 | def __repr__(self): |
| 650 | return "Database(name=%s, host=%s, tables=%s)" % ( |