-
Notifications
You must be signed in to change notification settings - Fork 605
Open
Labels
Description
This has been asked for several times but most recently in discord: https://discord.com/channels/1037340874172014652/1352309930010480791/1352309991088062569
We need a way to have a column in one table reference a column in another table, something like:
#[spacetimedb(table, name = "my_table", )]
pub struct MyTable {
#[primary_key]
#[auto_inc]
pub id: u64,
// ...
}
#[spacetimedb(table, name = "another_table")]
pub struct AnotherTable {
// WARNING: This is pseudocode and does not actually work.
#[foreign_key(MyTable)]
pub id: u64,
// ...
}
The user I referenced above has this specific case where they have a Vec<u64>
which each one of those u64
s references a key in another table. So it's more like something like this:
#[spacetimedb(table, name = "player_inventory")]
pub struct PlayerInventory {
#[foreign_key(Item), cascade_delete=false]
pub items: Vec<u64>
}
#[spacetimedb(table, name = "item")]
pub struct Item {
#[primary_key]
#[auto_inc]
pub id: u64,
pub name: String,
// ...
}
puttehi, stayhydated, urholaukkarinen, GGAlanSmithee, ChrisMcLain and 3 moreBenjaminPalko