datafiles icon indicating copy to clipboard operation
datafiles copied to clipboard

Support class relationships and foreign keys

Open wmusial opened this issue 2 years ago • 2 comments

datafiles package is great, but it stops short of providing support for object relationships and foreign keys. is that feature anywhere on the horizon? if not, would you be open to discussing it and providing guidance on how to implement it?

wmusial avatar Jun 22 '23 11:06 wmusial

That's an interesting idea. Perhaps you could provide some pseudocode of how it might look to use such a feature?

jacebrowning avatar Jun 23 '23 18:06 jacebrowning

Great package @jacebrowning, congrats!

This request could be done like this:

from dataclasses import dataclass

from datafiles import datafile


@datafile("parents/{self.name}/metadata.yml")
@dataclass
class Parent:
    name: str


@datafile("parents/{self.parent.name}/items/{self.name}/metadata.yml")
@dataclass
class Item:
    name: str
    parent: Parent
    count: int
    available: bool

It works fine for me!

ramibch avatar Mar 07 '24 09:03 ramibch