# Related or linked structures

**URL:** <https://discourse.julialang.org/t/related-or-linked-structures/85463>\
**Category:** General Usage\
**Tags:** dataframes, tullio, namedarrays, axiskeys, tensoroperations\
**Created:** [August 8, 2022, 7:45am UTC](https://discourse.julialang.org/t/related-or-linked-structures/85463 "2022-08-08T07:45:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [August 8, 2022, 7:45am UTC](https://discourse.julialang.org/t/related-or-linked-structures/85463/1 "2022-08-08T07:45:46Z")

</div>

Is it possible to connect data structures, similar to Primary-Key Foreign-Key connections in a relational database?

One way could be to have a type similar to enum that would limit a field to a given set of values. Using the type as a dimension label on multiple data structures (via via [NamedArrays](https://github.com/davidavdav/NamedArrays.jl) or [AxisKeys](https://github.com/mcabbott/AxisKeys.jl)) would implicitly “link” them together. Syntax like Einstein notation in [TensorOperations](https://github.com/Jutho/TensorOperations.jl), [Tullio](https://github.com/mcabbott/Tullio.jl) and [Einsum](https://github.com/ahwillia/Einsum.jl) could be used on the linked structure. Example

```julia
@PrimaryKey Currency AUD USD GBP EUR CAD
@PrimaryKey Scenario_Number 1:100

values[Currency, Date] := Value.( Deals, Rates ) |> sum

```

Where `Deals` and `Rates` are data structures using `Currency` and `Scenario_Number` as axis labels. The created data structure `values` also has them as element lables. Unlike Einstein notation, the indices only appear on the LHS of the equation since their use on the RHS is implicit.

The PrimaryKey type could also be used as a DataFrame row or column heading. Or as a structure field.
