entity.py
branchstable
changeset 7200 81fd6e40a6a8
parent 7139 20807d3d7cf6
child 7206 2723c52a0795
child 7210 29cd85f20ccb
equal deleted inserted replaced
7199:589801acf08e 7200:81fd6e40a6a8
   259         """
   259         """
   260         rql = 'INSERT %s X' % cls.__regid__
   260         rql = 'INSERT %s X' % cls.__regid__
   261         relations = []
   261         relations = []
   262         restrictions = set()
   262         restrictions = set()
   263         pending_relations = []
   263         pending_relations = []
       
   264         eschema = cls.e_schema
   264         for attr, value in kwargs.items():
   265         for attr, value in kwargs.items():
   265             if isinstance(value, (tuple, list, set, frozenset)):
   266             if attr.startswith('reverse_'):
       
   267                 attr = attr[len('reverse_'):]
       
   268                 role = 'object'
       
   269             else:
       
   270                 role = 'subject'
       
   271             assert eschema.has_relation(attr, role)
       
   272             rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr]
       
   273             if not rschema.final and isinstance(value, (tuple, list, set, frozenset)):
   266                 if len(value) == 1:
   274                 if len(value) == 1:
   267                     value = iter(value).next()
   275                     value = iter(value).next()
   268                 else:
   276                 else:
   269                     del kwargs[attr]
   277                     del kwargs[attr]
   270                     pending_relations.append( (attr, value) )
   278                     pending_relations.append( (attr, value) )