Skip to content

Link

v5.0.0 uses the object-oriented models

This page documents the legacy Link entity class. New code should use the object-oriented Link model.

Bases: Entity

Represents a link in Synapse.

WARNING - This class is deprecated and will no longer be maintained. Please use the Link model from synapseclient.models.Link instead.

Links must have a target ID and a parent. When you do synapseclient.Synapse.get on a Link object, the Link object is returned. If the target is desired, specify followLink=True in synapseclient.Synapse.get.

ATTRIBUTE DESCRIPTION
targetId

The ID of the entity to be linked

targetVersion

The version of the entity to be linked

parent

The parent project or folder

properties

A map of Synapse properties

annotations

A map of user defined annotations

local_state

Internal use only

TYPE: dict

Using this class

Creating an instance and storing the link

link = Link('targetID', parent=folder)
link = syn.store(link)
Migration to the object-oriented model

 

The legacy Link class is created and persisted through the Synapse client. The object-oriented Link model stores itself.

# Old approach (DEPRECATED)
# from synapseclient import Link
# link = syn.store(Link("syn123", parent="syn456"))

# New approach (RECOMMENDED)
from synapseclient import Synapse
from synapseclient.models import Link

syn = Synapse()
syn.login()

link = Link(target_id="syn123", parent_id="syn456").store()
print(link.id)
Source code in synapseclient/entity.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
@deprecated(
    version="4.14.0",
    reason="To be removed in 5.0.0. "
    "Use the Link model from synapseclient.models.Link instead.",
)
class Link(Entity):
    """
    Represents a link in Synapse.

    WARNING - This class is deprecated and will no longer be maintained. Please use the Link model from synapseclient.models.Link instead.

    Links must have a target ID and a parent. When you do [synapseclient.Synapse.get][] on a Link object,
    the Link object is returned. If the target is desired, specify followLink=True in synapseclient.Synapse.get.

    Attributes:
        targetId: The ID of the entity to be linked
        targetVersion: The version of the entity to be linked
        parent: The parent project or folder
        properties: A map of Synapse properties
        annotations: A map of user defined annotations
        local_state: Internal use only


    Example: Using this class
        Creating an instance and storing the link

            link = Link('targetID', parent=folder)
            link = syn.store(link)

    Example: Migration to the object-oriented model
         

        The legacy Link class is created and persisted through the Synapse
        client. The object-oriented Link model stores itself.

        ```python
        # Old approach (DEPRECATED)
        # from synapseclient import Link
        # link = syn.store(Link("syn123", parent="syn456"))

        # New approach (RECOMMENDED)
        from synapseclient import Synapse
        from synapseclient.models import Link

        syn = Synapse()
        syn.login()

        link = Link(target_id="syn123", parent_id="syn456").store()
        print(link.id)
        ```
    """

    _property_keys = Entity._property_keys + ["linksTo", "linksToClassName"]
    _local_keys = Entity._local_keys
    _synapse_entity_type = "org.sagebionetworks.repo.model.Link"

    def __init__(
        self,
        targetId=None,
        targetVersion=None,
        parent=None,
        properties=None,
        annotations=None,
        local_state=None,
        **kwargs,
    ):
        if targetId is not None and targetVersion is not None:
            kwargs["linksTo"] = dict(
                targetId=utils.id_of(targetId), targetVersionNumber=targetVersion
            )
        elif targetId is not None and targetVersion is None:
            kwargs["linksTo"] = dict(targetId=utils.id_of(targetId))
        elif properties is not None and "linksTo" in properties:
            pass
        else:
            raise SynapseMalformedEntityError("Must provide a target id")
        super(Link, self).__init__(
            concreteType=Link._synapse_entity_type,
            properties=properties,
            annotations=annotations,
            local_state=local_state,
            parent=parent,
            **kwargs,
        )