How to use the neomodel.RelationshipTo function in neomodel

To help you get started, we’ve selected a few neomodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neomodel / test / test_relative_relationships.py View on Github external
from neomodel import StructuredNode, RelationshipTo, StringProperty
from .test_relationships import Country


class Cat(StructuredNode):
    name = StringProperty()
    # Relationship is defined using a relative class path
    is_from = RelationshipTo('.test_relationships.Country', 'IS_FROM')


def test_relative_relationship():
    a = Cat(name='snufkin').save()
    assert a

    c = Country(code='MG').save()
    assert c

    # connecting an instance of the class defined above
    # the next statement will fail if there's a type mismatch
    a.is_from.connect(c)
    assert a.is_from.is_connected(c)
github neo4j-contrib / neomodel / test / test_cardinality.py View on Github external
class HairDryer(StructuredNode):
    version = IntegerProperty()


class ScrewDriver(StructuredNode):
    version = IntegerProperty()


class Car(StructuredNode):
    version = IntegerProperty()


class Monkey(StructuredNode):
    name = StringProperty()
    dryers = RelationshipTo('HairDryer', 'OWNS_DRYER', cardinality=ZeroOrMore)
    driver = RelationshipTo('ScrewDriver', 'HAS_SCREWDRIVER', cardinality=ZeroOrOne)
    car = RelationshipTo('Car', 'HAS_CAR', cardinality=OneOrMore)
    toothbrush = RelationshipTo('ToothBrush', 'HAS_TOOTHBRUSH', cardinality=One)


class ToothBrush(StructuredNode):
    name = StringProperty()


def test_cardinality_zero_or_more():
    m = Monkey(name='tim').save()
    assert m.dryers.all() == []
    assert m.dryers.single() is None
    h = HairDryer(version=1).save()

    m.dryers.connect(h)
    assert len(m.dryers.all()) == 1
github neo4j-contrib / neomodel / test / test_relationships.py View on Github external
from pytest import raises

from neomodel import (StructuredNode, RelationshipTo, RelationshipFrom, Relationship,
                      StringProperty, IntegerProperty, StructuredRel, One)


class PersonWithRels(StructuredNode):
    name = StringProperty(unique_index=True)
    age = IntegerProperty(index=True)
    is_from = RelationshipTo('Country', 'IS_FROM')
    knows = Relationship(u'PersonWithRels', 'KNOWS')  # use unicode to check issue

    @property
    def special_name(self):
        return self.name

    def special_power(self):
        return "I have no powers"


class Country(StructuredNode):
    code = StringProperty(unique_index=True)
    inhabitant = RelationshipFrom(PersonWithRels, 'IS_FROM')
    president = RelationshipTo(PersonWithRels, 'PRESIDENT', cardinality=One)
github neo4j-contrib / neomodel / test / test_match_api.py View on Github external
INCOMING, DateTimeProperty, IntegerProperty, RelationshipFrom, RelationshipTo,
    StringProperty, StructuredNode, StructuredRel
)
from neomodel.match import NodeSet, QueryBuilder, Traversal
from neomodel.exceptions import MultipleNodesReturned


class SupplierRel(StructuredRel):
    since = DateTimeProperty(default=datetime.now)
    courier = StringProperty()


class Supplier(StructuredNode):
    name = StringProperty()
    delivery_cost = IntegerProperty()
    coffees = RelationshipTo('Coffee', 'COFFEE SUPPLIERS')  # Space to check for escaping


class Coffee(StructuredNode):
    name = StringProperty(unique_index=True)
    price = IntegerProperty()
    suppliers = RelationshipFrom(Supplier, 'COFFEE SUPPLIERS', model=SupplierRel)


def test_filter_exclude_via_labels():
    Coffee(name='Java', price=99).save()

    node_set = NodeSet(Coffee)
    qb = QueryBuilder(node_set).build_ast()

    results = qb._execute()
github neo4j-contrib / neomodel / test / test_multi_class_relation.py View on Github external
from neomodel import StructuredNode, StringProperty, RelationshipTo


class Humanbeing(StructuredNode):
    name = StringProperty(unique_index=True)
    has_a = RelationshipTo(['Location', 'Nationality'], 'HAS_A')


class Location(StructuredNode):
    name = StringProperty(unique_index=True)


class Nationality(StructuredNode):
    name = StringProperty(unique_index=True)


def test_multi_class_rels():
    ne = Humanbeing(name='new news').save()
    lo = Location(name='Belgium').save()
    na = Nationality(name='British').save()

    ne.has_a.connect(lo)
github neo4j-contrib / neomodel / test / test_issue112.py View on Github external
from neomodel import StructuredNode, RelationshipTo


class SomeModel(StructuredNode):
    test = RelationshipTo('SomeModel', 'SELF')


def test_len_relationship():
    t1 = SomeModel().save()
    t2 = SomeModel().save()

    t1.test.connect(t2)
    l = len(t1.test.all())

    assert l
    assert l == 1
github xchem / fragalysis / frag / network / django_models.py View on Github external
smiles = StringProperty(unique_index=True)
    heavy_atom_count = IntegerProperty()
    ring_atom_count = IntegerProperty()
    ring_smiles = StringProperty()
    # Annotations of price and molecule id
    price = IntegerProperty()
    mol_id = StringProperty()


class Compound(BaseMolecule):
    """
    A molecule - a real purchasable molecule
    """
    fragments = RelationshipTo("Fragment", "FRAG")
    conformers = RelationshipTo("Conformer", "CONFEDGE")
    parent_molecules = RelationshipTo("Compound", "PARENTEDGE")


class Fragment(BaseMolecule):
    """
    A fragment - not a real molecule
    """
    molecules = RelationshipFrom(Compound, "FRAG", model=F2Edge)


class Conformer(StructuredNode):
    """
    The 3D conformer of a molecule - either Docked or imaginary
    """
    # Going to go with uuid - seems as good as anything - this connects to the Django database for 3D information
    unique_string = StringProperty(unique_index=True)
    conformer = RelationshipFrom(Compound, "CONFEDGE")
github neo4j-examples / paradise-papers-django / paradise_papers_search / fetch_api / models / officer.py View on Github external
RelationshipTo,
    Relationship
)

from .nodeutils import NodeUtils


class Officer(StructuredNode, NodeUtils):
    sourceID      = StringProperty()
    name          = StringProperty()
    country_codes = StringProperty()
    valid_until   = StringProperty()
    countries     = StringProperty()
    node_id       = StringProperty(index = True)
    addresses     = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
    entities      = RelationshipTo('.entity.Entity', 'OFFICER_OF')
    officers      = Relationship('.officer.Officer', None)



    @property
    def serialize(self):
        return {
            'node_properties': {
                'sourceID': self.sourceID,
                'name': self.name,
                'country_codes': self.country_codes,
                'valid_until': self.valid_until,
                'countries': self.countries,
                'node_id': self.node_id,
            },
        }
github neo4j-examples / paradise-papers-django / paradise_papers_search / fetch_api / models / other.py View on Github external
StringProperty,
    StructuredNode,
    RelationshipTo,
    Relationship
)

from .nodeutils import NodeUtils


class Other(StructuredNode, NodeUtils):
    sourceID    = StringProperty()
    name        = StringProperty()
    valid_until = StringProperty()
    node_id     = StringProperty(index = True)
    countries   = StringProperty()
    addresses   = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
    officers    = Relationship('.officer.Officer', None)
    entities    = Relationship('.entity.Entity', None)


    @property
    def serialize(self):
        return{
            'node_properties': {
                'sourceID': self.sourceID,
                'name': self.name,
                'countries': self.countries,
                'valid_until': self.valid_until,
                'node_id': self.node_id,
            },
        }
github romaintha / twitter / twitter / models.py View on Github external
id_str = neomodel.StringProperty(unique_index=True, required=True)
    name = neomodel.StringProperty(required=False)
    screen_name = neomodel.StringProperty(required=False)
    followers_count = neomodel.IntegerProperty(required=False)
    friends_count = neomodel.IntegerProperty(required=False)
    modified = neomodel.DateTimeProperty(required=False)
    created_at = neomodel.DateTimeProperty(required=False)
    description = neomodel.StringProperty(required=False)
    location = neomodel.StringProperty(required=False)
    coordinates = neomodel.ArrayProperty(required=False, default=[])
    time_zone = neomodel.StringProperty(required=False)
    url = neomodel.StringProperty(required=False)
    lang = neomodel.StringProperty(required=False)

    follows = neomodel.RelationshipTo('User', 'FOLLOWS')
    posts = neomodel.RelationshipTo('Tweet', 'POSTS')

    def save(self):
        self.modified = datetime.datetime.now()
        super(User, self).save()


class Hashtag(neomodel.StructuredNode):
    text = neomodel.StringProperty(unique_index=True, required=True)


class Link(neomodel.StructuredNode):
    url = neomodel.StringProperty(unique_index=True, required=True)