class Axlsx::Relationship

Packages automatically manage relationships.

A relationship defines a reference between package parts.

Initializes a new relationship.


  • source_obj (Object)

    see #source_obj

  • type (String)

    The type of the relationship

  • target (String)

    The target for the relationship

  • [Symbol] (Hash)

    a customizable set of options

Clear cached instances.

This should be called before serializing a package (see Package#serialize and Package#to_stream) to make sure that serialization is idempotent (i.e. Relationship instances are generated with the same IDs everytime the package is serialized).

Also, calling this avoids memory leaks (cached instances lingering around forever).

Keeps track of all instances of this class.

Generate and return a unique id (eg. `rId123`) Used for setting #Id.

The generated id depends on the number of cached instances, so using clear_cached_instances will automatically reset the generated ids, too.

The id of the relationship (eg. “rId123”). Most instances get their own unique id. However, some instances need to share the same id – see #should_use_same_id_as? for details.


Implement comparison of #Target based on normalized path names.

Whether this relationship should use the same id as `other`.

Instances designating the same relationship need to use the same id. We can not simply compare the #Target attribute, though: `foo/bar.xml`, `../foo/bar.xml`, `../../foo/bar.xml` etc. are all different but probably mean the same file (this is especially an issue for relationships in the context of pivot tables). So lets just ignore this attribute for now (except when #TargetMode is set to `:External` – then #Target will be an absolute URL and thus can safely be compared).


  • other (Relationship)

The source object the relations belongs to (e.g. a hyperlink, drawing, …). Needed when looking up the relationship for a specific object (see Axlsx::Relationships#for).

The location of the relationship target

The target mode of the relationship used for hyperlink type relationships to mark the relationship to an external resource TargetMode can be specified during initialization by passing in a :target_mode option Target mode must be :external for now.

serialize relationship


  • str (String) (defaults to: '')

Supported types are defined as constants in Axlsx:

The type of relationship

Relationship is referenced in 0 repositories