• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RM 1.1 Difference between xf_resource_field_value and xf_resource.custom_resource_fields?

DeltaHF

Well-known member
#1
I'm creating an add-on for the Resource Manager, and found that the xf_resource_field_value table and the custom_resource_fields column in the xf_resource table appear to contain the same data in slightly different formats.

Just curious: why is this data duplicated?
 

Mike

XenForo developer
Staff member
#3
In most cases, if you see one table with a "structured" version of data and another where it's serialized/JSON, the serialized data is simply a cache -- the structured version is considered the canonical.
 

DeltaHF

Well-known member
#4
Cool to know; thanks.

Is there a reason xf_resource_field_value stores custom fields in discreet rows instead of columns?
 

Chris D

XenForo developer
Staff member
#5
How could it store them any other way?

What additional columns would be needed?

Any additional data that needs to be fetched can be done using joins.
 

DeltaHF

Well-known member
#6
I expected each field value for each to be stored in its own column per resource_id:

Code:
+-------------+-------------------+-------------------+----
+ resource_id | custom_field_id_1 | custom_field_id_2 | ...
+ 1           | "foo"             | "bar"             | ...
+-------------+-------------------+-------------------+----
Instead, each field per resource_id is stored in its own row:

Code:
+-------------+------------------+-------------+----
+ resource_id + field_id         + field_value + ...
+ 1           + "custom_field_1" + "foo"       + ...
+ 1           + "custom_field_2" + "bar"       + ...
+-------------+------------------+-------------+----
I suppose this is because different resources could, depending upon their parent category, contain entirely different custom fields?