554 return results |
554 return results |
555 |
555 |
556 def insert_relation_defs(self): |
556 def insert_relation_defs(self): |
557 session = self.session |
557 session = self.session |
558 repo = session.repo |
558 repo = session.repo |
|
559 edited_entities = {} |
|
560 relations = {} |
559 for subj, rtype, obj in self.relation_defs(): |
561 for subj, rtype, obj in self.relation_defs(): |
560 # if a string is given into args instead of an int, we get it here |
562 # if a string is given into args instead of an int, we get it here |
561 if isinstance(subj, basestring): |
563 if isinstance(subj, basestring): |
562 subj = typed_eid(subj) |
564 subj = typed_eid(subj) |
563 elif not isinstance(subj, (int, long)): |
565 elif not isinstance(subj, (int, long)): |
565 if isinstance(obj, basestring): |
567 if isinstance(obj, basestring): |
566 obj = typed_eid(obj) |
568 obj = typed_eid(obj) |
567 elif not isinstance(obj, (int, long)): |
569 elif not isinstance(obj, (int, long)): |
568 obj = obj.entity.eid |
570 obj = obj.entity.eid |
569 if repo.schema.rschema(rtype).inlined: |
571 if repo.schema.rschema(rtype).inlined: |
570 entity = session.entity_from_eid(subj) |
572 if subj not in edited_entities: |
571 edited = EditedEntity(entity) |
573 entity = session.entity_from_eid(subj) |
|
574 edited = EditedEntity(entity) |
|
575 edited_entities[subj] = edited |
|
576 else: |
|
577 edited = edited_entities[subj] |
572 edited.edited_attribute(rtype, obj) |
578 edited.edited_attribute(rtype, obj) |
573 repo.glob_update_entity(session, edited) |
|
574 else: |
579 else: |
575 repo.glob_add_relation(session, subj, rtype, obj) |
580 if rtype in relations: |
|
581 relations[rtype].append((subj, obj)) |
|
582 else: |
|
583 relations[rtype] = [(subj, obj)] |
|
584 repo.glob_add_relations(session, relations) |
|
585 for edited in edited_entities.itervalues(): |
|
586 repo.glob_update_entity(session, edited) |
576 |
587 |
577 |
588 |
578 class QuerierHelper(object): |
589 class QuerierHelper(object): |
579 """helper class to execute rql queries, putting all things together""" |
590 """helper class to execute rql queries, putting all things together""" |
580 |
591 |