[drupal-devel] Random: Drupal Relationships
In working with taxonomy, I'm now leaning toward the following as a replacement for term_node (I'm using words here for readability, but assume all "id" columns are, in fact, numbers): tid | uid | type | id ----------------------------- cat | morbus | image | 67 cat | moshe | node | 17 dog | killes | comment | 129 cool | dries | user | 1 which would also satisfy node/899 as well. But, my work with librarian tech and the LibDB project (now halted) has resurfaced because of the above. The "type / id" mentality was used in LibDB's relationship table, but was expanded to include a generic two way relationship. I'd like to bounce the same idea for Drupal core and see what you think. Here is the table structure and example data (again, assume that if an ID makes sense in the column, it'd be there, and that "f" is "from", "r" is "relationship" and "t" is "to"). I've include explanatory sentences under each column: f_type | f_data | r_type | r_data | r_who | t_type | t_data ------------------------------------------------------------ term | cat | taxo | | morb | image | 67 "taxonomy relationship between term cat and image 67, by morbus" term | dog | taxo | | moshe | node | 17 "taxonomy relationship between term dog and node 17, by moshe user | morb | user | friend | moshe | user | dries "user relationship: moshe asserts that user morbus is a friend of user dries" user | jonbob | user | lover | morb | user | dries "user relationship: morbus asserts that user jonbob is a lover of user dries" user | walkah | rating | 6 | walkah | node | 16 user | morbus | rating | 10 | morbus | user | dries "user walkah has given node 16 a rating of 6" "user morbus has given user dries a rating of 10" And so on and so forth. In essence: * anything can relate to anything else. * the types of relationship are defined by the module. * relationships may have additional data (rating, "friend"). The above is pretty powerful (but at what cost - who knows a lot about gigantic tables - is the lookup insanely bad?), and is flexible enough to handle a lot of features that would normally require overhauling existing tables or creating new ones entirely. Two recent modules I've seen, for example, serve the following purpose: * different URLs use different templates (sections module, I think). * nodes can be in a child/parent rel (node_relativity, I think). I'm assuming they both do this magic with new tables. But, what about: url | /forums | sections | | morbus | template | happy.tpl node | 16 | relativity | child | morbus | node | 19 node | 18 | relativity | inspired | morbus | node | 25 And so on. -- Morbus Iff ( you, me, eropuri? aawwwwwWWWw yYeahahhHHAhhh ) Technical: http://www.oreillynet.com/pub/au/779 Culture: http://www.disobey.com/ and http://www.gamegrene.com/ icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus
Morbus Iff wrote:
tid | uid | type | id
I seriously considered adding a "type" column to the relativity table for future expansion. Only considering the needs of relativity module, this would not be needed, though. The rules defining relationships, however, require much more flexibility, and Aran Deltac has proposed a table structure for holding per-node relationship data: CREATE TABLE relativity_variable ( vid tinyint(10) unsigned NOT NULL auto_increment, nid int(10) unsigned NOT NULL default '0', node_type varchar(32) default '', node_relation tinyint unsigned default 0, var_namespace varchar(32) default '', var_key varchar(32) default '', PRIMARY KEY (vid), KEY (var_namespace(2),var_key(6)), KEY (node_type,node_relation) ); CREATE TABLE relativity_variable_value ( vid tinyint(10) unsigned NOT NULL, var_value longtext default '', PRIMARY KEY (vid) ); This may be too relativity.module-specific for a generic relationship table. The var_namespace would basically keep separate features form polluting the namespace of other features. This could be "taxonomy", "relativity", "book", "section", "friend", etc. The performance of maintaining separate "variable" and "variable_value" tables would need to be assessed against putting the longtext "value" as part of the same "variable" table. Don't let the naming convention throw you off, "relativity_variable" would hold per-relationship rules (per-node, per-user, etc) and other meta-information. It would allow for multiple rules to govern each relationship, too ("max_child_nodes" => 10, "allowed_child_types" => "page,story,image", or "friend_type" => "coworker", "friend_level" => "acquaintance").
Here is the table structure and example data (again, assume that if an ID makes sense in the column, it'd be there, and that "f" is "from", "r" is "relationship" and "t" is "to"). I've include explanatory sentences under each column:
f_type | f_data | r_type | r_data | r_who | t_type | t_data ------------------------------------------------------------ term | cat | taxo | | morb | image | 67 "taxonomy relationship between term cat and image 67, by morbus"
term | dog | taxo | | moshe | node | 17 "taxonomy relationship between term dog and node 17, by moshe
user | morb | user | friend | moshe | user | dries "user relationship: moshe asserts that user morbus is a friend of user dries"
* anything can relate to anything else. * the types of relationship are defined by the module. * relationships may have additional data (rating, "friend").
The above is pretty powerful (but at what cost - who knows a lot about gigantic tables - is the lookup insanely bad?), and is flexible enough to handle a lot of features that would normally require overhauling existing tables or creating new ones entirely. Two recent modules I've seen, for example, serve the following purpose:
* different URLs use different templates (sections module, I think). * nodes can be in a child/parent rel (node_relativity, I think).
I'm assuming they both do this magic with new tables. But, what about:
url | /forums | sections | | morbus | template | happy.tpl node | 16 | relativity | child | morbus | node | 19 node | 18 | relativity | inspired | morbus | node | 25
And so on.
I don't know what this would do to performance on a system with a lot of relationships. I could see a site with a few thousand nodes, a thousand or so users, each with an average buddylist of 10 users, a large folksonomy and a book or two getting pretty large. Indexes could obviously take care of much of this, but constantly hitting a single table of some 50k records might hinder scalability to some degree. To your point, this would need to be tested by someone more familiar with large tables. I, too, am interested to see what a seasoned DBA would have to say about this arrangement. -Mark
Hi there, What you propose, is a *very* interesting idea, but it is still very academic, therefore I want to present three Drupal use cases that IMO should be covered by this new relation 'thing'. If these are all covered it will: * save code * introduce better generalisation * introduce cross-site relations 1) Outlining (now called books). 2) Filed_under (simple taxonomy) 3) Taxonomy (complex taxonomy) ad1) IN essence its a simple node to node relation with some additional information. In your scheme it would look like: f_type | f_data | r_type | r_data | r_who | t_type | t_data node | 12 | parent | 5 | | node | 16 node | 22 | parent | 8 | | node | 12 node | 12 | parent | 4 | | node | 50 would make an outline of: -22 -- 12 ----50 ----16 The r_data is what we now call "weights". ad2) term | dog | taxo | | moshe | node | 17 "taxonomy relationship between term dog and node 17, by moshe ad3) term | dog | taxo | | moshe | node | 17 term | teckel | parent | | moshe | term | 100 taxo tree will be - dog ----teckel node is related to dog. Hope this will convince more developers that this idea is GREAT. Ber ------------------ ON a sidenote: I have been experimenting with relativities for a while too now. I coded a node to node relation a while back, and recently made a module that uses taxonomy for node to node parent-child relations: (one of thse badly named...) clipper. My plans are to continue on this road in near future, The site that uses these relations is Remixreading.org. It needs parent-child relations betwwen pieces of art. My plans were, to merge clipper into books, and call it outlines. outline.module or so. However, your post shines some new light over these plans: Relate anything. Op zaterdag 12 maart 2005 00:53, schreef Morbus Iff:
In working with taxonomy, I'm now leaning toward the following as a replacement for term_node (I'm using words here for readability, but assume all "id" columns are, in fact, numbers):
tid | uid | type | id ----------------------------- cat | morbus | image | 67 cat | moshe | node | 17 dog | killes | comment | 129 cool | dries | user | 1
which would also satisfy node/899 as well. But, my work with librarian tech and the LibDB project (now halted) has resurfaced because of the above. The "type / id" mentality was used in LibDB's relationship table, but was expanded to include a generic two way relationship. I'd like to bounce the same idea for Drupal core and see what you think.
Here is the table structure and example data (again, assume that if an ID makes sense in the column, it'd be there, and that "f" is "from", "r" is "relationship" and "t" is "to"). I've include explanatory sentences under each column:
f_type | f_data | r_type | r_data | r_who | t_type | t_data ------------------------------------------------------------ term | cat | taxo | | morb | image | 67 "taxonomy relationship between term cat and image 67, by morbus"
term | dog | taxo | | moshe | node | 17 "taxonomy relationship between term dog and node 17, by moshe
user | morb | user | friend | moshe | user | dries "user relationship: moshe asserts that user morbus is a friend of user dries"
user | jonbob | user | lover | morb | user | dries "user relationship: morbus asserts that user jonbob is a lover of user dries"
user | walkah | rating | 6 | walkah | node | 16 user | morbus | rating | 10 | morbus | user | dries "user walkah has given node 16 a rating of 6" "user morbus has given user dries a rating of 10"
And so on and so forth. In essence:
* anything can relate to anything else. * the types of relationship are defined by the module. * relationships may have additional data (rating, "friend").
The above is pretty powerful (but at what cost - who knows a lot about gigantic tables - is the lookup insanely bad?), and is flexible enough to handle a lot of features that would normally require overhauling existing tables or creating new ones entirely. Two recent modules I've seen, for example, serve the following purpose:
* different URLs use different templates (sections module, I think). * nodes can be in a child/parent rel (node_relativity, I think).
I'm assuming they both do this magic with new tables. But, what about:
url | /forums | sections | | morbus | template | happy.tpl node | 16 | relativity | child | morbus | node | 19 node | 18 | relativity | inspired | morbus | node | 25
And so on. Regards, Bèr -- [ Bèr Kessels | Drupal services www.webschuur.com ]
Morbus Iff wrote:
In working with taxonomy, I'm now leaning toward the following as a replacement for term_node (I'm using words here for readability, but assume all "id" columns are, in fact, numbers):
tid | uid | type | id ----------------------------- cat | morbus | image | 67 cat | moshe | node | 17 dog | killes | comment | 129 cool | dries | user | 1
Difficult to say without proper benchmarking. I'm sure some relations are better captured in separate tables, while for some relations it might be beneficial to use a single table. It all depends on how you want to use (query) the data, and how frequent. Personally, I'd start off with extending taxonomy for folksonomies and nothing more. -- Dries Buytaert :: http://www.buytaert.net/
Morbus Iff wrote:
And so on and so forth. In essence:
* anything can relate to anything else. * the types of relationship are defined by the module. * relationships may have additional data (rating, "friend").
The above is pretty powerful (but at what cost - who knows a lot about gigantic tables - is the lookup insanely bad?), and is flexible enough to handle a lot of features that would normally require overhauling existing tables or creating new ones entirely.
this reminds me much of http://lists.drupal.org/archives/drupal-devel/2003-05/msg00042.html just a random thought :) -- ax Cameron: [singing] When Cameron was in Egypt's land..."let my Cameron go!"
Axel Kollmorgen wrote:
this reminds me much of http://lists.drupal.org/archives/drupal-devel/2003-05/msg00042.html
Wow, that was an interesting read. When developing the relativity module, I took the parent/child approach to defining relationships, which didn't seem to be brought up much (just uni-directional and bi-directional). We're now working on per-node options (as opposed to per-node-type options) for specifying relationship constraints and meta-data. I didn't know about drupal when this thread was discussed, but I am impressed with the ideas that were discussed so long ago. In fact, I was truly surprised that such a generic framework didn't already exist. Were any modules developed as a result of that thread? Thanks for the link. -Mark
Mark wrote:
this reminds me much of http://lists.drupal.org/archives/drupal-devel/2003-05/msg00042.html
Wow, that was an interesting read. [...] Were any modules developed as a result of that thread?
apart from Stephane's org_informations.module [1] which started that thread [2] - i don't think so. you could try contacting him or Al(astair Maw) to know for sure. [1] http://cvs.drupal.org/viewcvs/drupal/contributions/modules/org_informations/... [2] http://lists.drupal.org/archives/drupal-devel/2003-05/msg00036.html -- ax Going to church does not make you a Christian anymore than going to the garage makes you a car
participants (5)
-
Axel Kollmorgen -
Bèr Kessels -
Dries Buytaert -
Mark -
Morbus Iff