
dm_add_fk()
marks the specified columns as the foreign key of table table
with
respect to the primary key of table ref_table
.
If check == TRUE
, then it will first check if the values in columns columns
are a subset
of the values of the primary key in table ref_table
.
dm_rm_fk()
can remove either one reference between two tables, or all references at once, if argument column = NULL
.
All arguments may be provided quoted or unquoted.
dm_add_fk(dm, table, columns, ref_table, check = FALSE)dm_rm_fk(dm, table, columns, ref_table)
A dm
object.
A table in the dm
.
For dm_add_fk()
: The columns of table
which are to become the foreign key columns that
reference the primary key of ref_table
.
For dm_rm_fk()
: The columns of table
that should no longer be referencing the primary key of ref_table
.
If NULL
, all columns will be evaluated.
For dm_add_fk()
: The table which table
will be referencing.
This table needs to have a primary key set.
For dm_rm_fk()
: The table that table
is referencing.
Boolean, if TRUE
, a check will be performed to determine if the values of
column
are a subset of the values of the primary key column of ref_table
.
For dm_add_fk()
: An updated dm
with an additional foreign key relation.
For dm_rm_fk()
: An updated dm
without the given foreign key relation.
Currently, keys consisting of more than one column are not supported. This feature is planned for dm 0.2.0. The syntax of these functions will be extended but will remain compatible with current semantics.
Other foreign key functions:
dm_enum_fk_candidates()
,
dm_get_all_fks()
,
dm_get_fk()
,
dm_has_fk()
Other foreign key functions:
dm_enum_fk_candidates()
,
dm_get_all_fks()
,
dm_get_fk()
,
dm_has_fk()
# NOT RUN {
if (rlang::is_installed("nycflights13")) {
nycflights_dm <- dm(
planes = nycflights13::planes,
flights = nycflights13::flights
)
} else {
message("Using mock-up data, install the nycflights13 package to fix.")
nycflights_dm <- dm(
planes = tibble(tailnum = character()),
flights = tibble(tailnum = character())
)
}
nycflights_dm %>%
dm_draw()
nycflights_dm %>%
dm_add_pk(planes, tailnum) %>%
dm_add_fk(flights, tailnum, planes) %>%
dm_draw()
dm_nycflights13(cycle = TRUE) %>%
dm_rm_fk(flights, dest, airports) %>%
dm_draw()
# }
Run the code above in your browser using DataLab