问题描述
使用py2neo或cypher设置关系属性后,是否可以更改它?我正在创建一个库存跟踪器,一旦项目为"CHECKED_OUT",则关系中的一个名为"status"的属性将设置为"True".理想情况下,一旦退回或签入商品,我想将"status"属性更改为"False".这样,我就可以跟踪该项目,并防止它被两次检出.
Is there a way to change a relationship property once it has been set using py2neo or cypher? I'm creating an inventory tracker and once an item is "CHECKED_OUT" a property called "status" in the relationship is set to "True". Ideally, once the item is returned or checked in, I'd like to change the "status" property to "False". This way I can keep track of the item and prevent it from being checked out twice.
这是我为结帐交易创建关系的代码:
Here is my code for creating the relationship for a checkout transaction:
def check_out(self, barcode):
emp = self
item = barcode
id = str(uuid.uuid4())
timestamp = int(datetime.now().strftime("%s"))
date = datetime.now().strftime("%F")
status=True
rel = Relationship(emp, "CHECKED_OUT", item, id=id, timestamp=timestamp, date=date, status=status)
if not(graph.create_unique(rel)):
return True
else:
return False
我已经阅读了py2neo API,但似乎找不到答案.如果修改关系是错误的方法,您能提供更好的方法吗?
I've read through the py2neo API and I can't seem to find the answer. If modifying the relationship is the wrong approach, can you offer a better one?
推荐答案
与此类似的方法应该起作用:
Something along this line should work:
def check_in(self, barcode):
item = barcode
# get the relationship
for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):
# set property
rel.properties["status"] = False
rel.push()
请参见match()
: http://py2neo.org/2.0/essentials .html#py2neo.Graph.match
和properties
: http://py2neo.org/2.0/essentials .html#py2neo.Relationship.properties
这篇关于修改或更改py2neo中的关系属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!