When a column serves as both a primary and foreign key, dm refuses to flatten the model. Below is a minimal example.
mydm <- dm(
x = tibble(a = 1, b = 2),
y = tibble(c = 2, d = 3),
z = tibble(e = 2, f = 4)
) %>%
dm_add_pk(x, a) %>%
dm_add_pk(y, c) %>%
dm_add_pk(z, e) %>%
dm_add_fk(x, b, y) %>%
dm_add_fk(y, c, z)
Diagram:
mydm %>% dm_draw(view_type = "all")

Flattening the model
mydm %>% dm_flatten_to_tbl(x, .recursive = TRUE)
Output:
Error in `join()`:
! Join columns in `x` must be present in the data.
✖ Problem with `c`.
Run `rlang::last_trace()` to see where the error occurred.
Expected output:
# A tibble: 1 × 4
a b d f
<dbl> <dbl> <dbl> <dbl>
1 1 2 3 4