How to use [magic.db.mysql.foreign_keys]
This slot returns all foreign keys for the specified [connection-string]/[database]/[table] combination. Below is example usage.
signal:magic.db.mysql.foreign_keys
connection-string:generic
database:magic
table:users_roles
The above would return all foreign keys in your “users_roles” table, resulting in something resembling the following.
signal
""
column:role
foreign_table:roles
foreign_column:name
""
column:user
foreign_table:users
foreign_column:username
In the above result we can see how the “role” column in the “users_roles” table for instance has a foreign key declaration pointing towards the “name” column in the “roles” table, and similarly for the “user” column pointing towards the “users” table’s “username” column. The resulting values imply the following.
- [column] - Name of column in table you’re querying
- [foreign_table] - Name of table the column is referencing
- [foreign_column] - Name of column in foreign table the column is referencing