How RelationshipSupport manages OOXML relationships
masterThe RelationshipSupport module is a mixin used by OOXML objects to automate the loading and saving of _rels files. It works through several key mechanisms:
- Definition: Classes use
define_relationship(klass, accessor)to register which class/accessor should be used when a specific relationship is encountered. - Loading: When
load_relationships(dir_path, base_file_name)is called, it loads the.relsfile and iterates through the relationships. It then usesattach_relationshipto map the loaded files back to the object. - Attachment Logic:
- If a specific accessor is defined, the related file is assigned to that accessor.
- If the relationship is known but has no specific accessor, it is stored in
generic_storage. - If the relationship type is unknown to the class, it is stored in
generic_storageand a warning may be issued.
- Collection: The
collect_related_objectsmethod recursively gathers all related objects, including those ingeneric_storageand those managed by arelationship_container, to ensure the entire object tree is preserved during serialization.