This function adds primary and foreign keys to a 'dm' object automatically, assuming the names of the tables and keys follow these rules:
For each table, the primary key has the same name as the table with the prefix
_id. For example the tablexhas a primary key namedx_id.If an
_idcolumn exists in a table which name is different than the prefix of_id, then that column is a foreign key linking to another table. For example, in the tablex_id, the columny_idis a foreign key linking to the tabley.
Examples
dm <- dm::dm(x = data.frame(x_id = 1, y_id = 2), y = data.frame(y_id = 2))
add_keys(dm)
#> ── Metadata ────────────────────────────────────────────────────────────────────
#> Tables: `x`, `y`
#> Columns: 3
#> Primary keys: 2
#> Foreign keys: 1