question

erik-wagner avatar image
erik-wagner asked

Best Practice for Parent/Child data

Hi,
I was wondering if there was a recommended/best practice method of setting up data that has a parent/child type relationship to it. To give an example of what I mean, let's say I have a catalog and in the catalog are three items, 'street', 'city' and 'country'. When a player/character is created they are assigned the street from the catalog that has custom data added to it, a city that the street exists in and a country that the city exists in.
So, their street item has json data with 'ownercity' and their city has a field with 'ownercountry'. i.e.

Street {

"StreetName": "Anywhere Street",

"OwnerCity": "Capital City" }

City {

"CityName": "Capital City",

"OwnerCountry": "Anywhereistan" }

Country {

"CountryName": "Anywhereistan"

"OwnerCharacter": "MyCharacter" }

Is this the best way to handle such a situation or is there another way to arrange catalog items that would be better/easier. Keep in mind that there are a few pieces of custom data in the catalog but for the most part things get thoroughly customized once they are created/assigned to a character. Also, if it makes a difference, the relationship between street/city is constant but ownership by character can change based on gameplay.

I have initially been thinking this as the way to set things up but it also feels like maybe it is unnecessarily difficult. Would a better method for keeping this relationship between the items be to assign a tag to them and operate on that?

I know this is kind of an odd/open-ended question; just don't want to reinvent the wheel if someone has seen or knows of a better way to do this.

Thanks in advance!

data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The most immediate thing I'd call out is that this looks like it's replicating data unnecessarily (and potentially in a way that'll give you headaches later). Since Streets are in Cities and Cities are in Countries in your model, you really don't want to have the owner City and Country in every single record. Instead, have a lookup table of data - Streets to Cities, Cities to Countries, etc. - and have that live in a single location (like Title Data). That way, you just store the street info on the item, and the lookup gets you the rest. That way, if you have to change something in the relationship later (like you find that a Street or City was mis-tagged), you can make changes without having to make changes to every since item record.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

erik-wagner avatar image erik-wagner commented ·

@brendan, thanks! I had a feeling I'd made it needlessly complex.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.