x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Relationships - Under the Hood

This article seeks to demystify how EE (as of 1.6) creates relationships between weblogs (or sections) with the “Relationship” field type. It also details how to create relationships manually by directly accessing EE database tables.

The exp_relationships Table
The exp_relationships table holds the bulk of the data required to establish relationships between weblogs. In addition to an exp_relationships record, a relationship also requires that one field be set in the exp_weblog_data record of the parent entry.

The structure of the exp_relationships table is as follows.

rel_id: a unique id for the relationship record (this is auto-generated by MySQL)
rel_parent_id: the entry_id for the parent record
rel_child_id: the entry_id for the related child record
rel_type: the type of relationship (i.e. “blog”)
rel_data: auto-generated cache data to speed up regular relationship page builds
reverse_rel_data: similar cache data for reverse relationship pages

Manually Creating a Relationship
To establish a weblog or section relationship, only the first FOUR fields must be populated. EE generates the cached data as required.

In addition, the parent’s exp_weblog_data record must be set to contain the rel_id value of the exp_relationships record. This value is set in the field_id_### field that corresponds to the parent weblog’s relationship field.

Relationships Example
On a magazine site, two distinct weblogs hold articles and authors. A relationship field (“author”) is added to the article weblog to point to the corresponding author record. This relationship field is field_id_23.

The article “The New iBlender” (articles weblog, entry_id 332) was written by Ken Mac (authors weblog, entry_id 75).

In this example, the final relationship is established by the following field data:

<u>exp_relationships</u>
rel_id: 783 (auto-generated)
rel_parent_id: 332 (article record entry_id)
rel_child_id: 75 (author record entry_id)
rel_type: “blog”

<u>exp_weblog_data</u> (for parent entry_id 332, in the article weblog’s “author” field)
field_id_23: 783 (rel_id value from exp_relationships)

Category:Database

Categories: