Database structure and associations for open-ended data and data types

穿精又带淫゛_ 提交于 2019-12-12 17:45:26

问题


I'm trying to build a custom CMS tool (yes I know - ANOTHER CMS) where the users can create as many nested "nodes" as they want.

Example "Nodes": Restaurants, People, Shoes, Continents ... anything. Within each Node, there can be as many sub nodes as needed and so on and so forth.

While looking through Wordpress, Drupal... etc etc, I keep seeing tables like "taxonomy", and "terms".

This seems like a "normal" thing, but I can't wrap my head around how it should be done or how they're doing it. I assume these tables are related to the overall structure and table relationships, but... searches online come up shy of explaining what's actually going on or how best I would go about designing my database for this kind of structure.


Ideas I've had so far (that obviously aren't flushed out or I wouldn't be here asking):

1) Store known data types and bindModel(): Create tables like data_locations and data_texts that would have fields respective of their data. So - in the data_locations table, I'd have city, and longitude, and address. And in the data_texts table, I'd have title, subtitle, content, author.

Then, each time they created a new "Node", they could pick what kind of data-types it should have, and I would use bindModel() to create the associations (I guess?).

This wouldn't be as flexible, but maybe easier to manage, and faster to run queries on...etc? Dunno.

2) Custom fields for each Node with single "data" table: Have a data table, and a fields table... each node would haveMany fields - each with a type and maxLength...etc. Then, in the admin, I'd list those fields, and each chunk of data title, shoe_size...etc would have a row in the data table that related to the node and to the field.

This one seems more like what I THINK the "taxonomy" thing is - but again, I really have no idea.


回答1:


Which database are you considering? Graph databases tend to be more natural for this kind of thing in my opinion.

In a relational database it is tricky. Nesting queries of arbitrary depth are not natural (but doable), dynamic schema are also unnatural (see 'EAV schemas' via google to see the arguments around that) and are very difficult to query well.

Have a look at neo4j. I think you can express your requirement directly and naturally.



来源:https://stackoverflow.com/questions/11911271/database-structure-and-associations-for-open-ended-data-and-data-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!