从py2neo网站的例子: http://py2neo.org/v3/ogm.html
class Movie(GraphObject):
__primarykey__ = "title"
title = Property()
tag_line = Property("tagline")
released = Property()
actors = RelatedFrom("Person", "ACTED_IN")
directors = RelatedFrom("Person", "DIRECTED")
producers = RelatedFrom("Person", "PRODUCED")
class Person(GraphObject):
__primarykey__ = "name"
name = Property()
born = Property()
acted_in = RelatedTo(Movie)
directed = RelatedTo(Movie)
produced = RelatedTo(Movie)
有没有办法指定关系的属性? 例如。我想为这段关系增加权重。
由于
答案 0 :(得分:0)
实例化p = Person()
对象后,这是help(p.acted_in.add)
的输出:
Signature: p.acted_in.add(obj, properties=None, **kwproperties)
Docstring:
Add a related object.
:param obj: the :py:class:`.GraphObject` to relate
:param properties: dictionary of properties to attach to the relationship (optional)
:param kwproperties: additional keyword properties (optional)
File: /usr/local/lib/python3.6/site-packages/py2neo/ogm.py
Type: method```
因此,如果您实例化了m = Movie()
个对象,则可以调用例如
p.acted_in.add(m, properties={"weight": 0.74})