Learn R Programming

dm (version 0.0.6)

dm_add_fk: Add a reference from one table of a dm to another

Description

Add a reference from one table of a dm to another

Usage

dm_add_fk(dm, table, column, ref_table, check = FALSE)

Arguments

dm

A dm object.

table

A table in the dm.

column

The column of table which is to become the foreign key column and reference the primary key of ref_table.

ref_table

The table which table is referencing. This table needs to have a primary key set.

check

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.

Value

An updated dm with an additional foreign key relation.

See Also

Other foreign key functions: dm_enum_fk_candidates(), dm_get_all_fks(), dm_get_fk(), dm_has_fk(), dm_rm_fk()

Examples

Run this code
# NOT RUN {
library(dplyr)
iris_key <- mutate(iris, key = row_number()) %>%
  select(key, everything())
dm(iris_1 = iris_key, iris_2 = iris_key) %>%
  dm_add_pk(iris_2, key) %>%
  dm_add_fk(iris_1, key, iris_2)
# }

Run the code above in your browser using DataLab