def add_cast(self, cast_info): try: from actors import Actor except ImportError: from coactors.actors import Actor query = """MERGE (t:Title {uid: $uid}) ON CREATE SET t += {title: $title, released: $released, title_type: $title_type} SET t.children_known = True WITH t CALL { WITH t UNWIND $batch as row MERGE (_:Actor {uid: row.uid}) ON CREATE SET _ += {name: row.name} MERGE (_)-[:ACTED_IN]->(t) RETURN _ }""" params = { "title": self.title, "uid": self.uid, "released": self.released, "title_type": self.title_type } batch = [] for i in range(0, len(cast_info)): batch.append({ "uid": cast_info[i]["uid"], "name": cast_info[i]["name"] }) params['batch'] = batch return Actor.match(graph).raw_query(query, params)
def get_cast(self): try: from actors import Actor except ImportError: from coactors.actors import Actor return Actor.match(graph).raw_query( "MATCH(t:Title {uid: $uid})<-[:ACTED_IN]-(_:Actor) ", {"uid": self.uid})