entity.py
changeset 2880 bfc8e1831290
parent 2845 660caa3ddc4f
parent 2877 e469f3602858
child 2968 0e3460341023
equal deleted inserted replaced
2869:0cb160fd3cdf 2880:bfc8e1831290
   150             if not rschema.is_final():
   150             if not rschema.is_final():
   151                 # XXX this does not handle several destination types
   151                 # XXX this does not handle several destination types
   152                 desttype = rschema.objects(eschema.type)[0]
   152                 desttype = rschema.objects(eschema.type)[0]
   153                 card = rschema.rproperty(eschema, desttype, 'cardinality')[0]
   153                 card = rschema.rproperty(eschema, desttype, 'cardinality')[0]
   154                 if card not in '?1':
   154                 if card not in '?1':
       
   155                     self.warning('bad relation %s specified in fetch attrs for %s',
       
   156                                  attr, self.__class__)
   155                     selection.pop()
   157                     selection.pop()
   156                     restrictions.pop()
   158                     restrictions.pop()
   157                     continue
   159                     continue
   158                 if card == '?':
   160                 # XXX we need outer join in case the relation is not mandatory
   159                     restrictions[-1] += '?' # left outer join if not mandatory
   161                 # (card == '?')  *or if the entity is being added*, since in
       
   162                 # that case the relation may still be missing. As we miss this
       
   163                 # later information here, systematically add it.
       
   164                 restrictions[-1] += '?'
   160                 # XXX user.req.vreg iiiirk
   165                 # XXX user.req.vreg iiiirk
   161                 destcls = user.req.vreg['etypes'].etype_class(desttype)
   166                 destcls = user.req.vreg['etypes'].etype_class(desttype)
   162                 destcls._fetch_restrictions(var, varmaker, destcls.fetch_attrs,
   167                 destcls._fetch_restrictions(var, varmaker, destcls.fetch_attrs,
   163                                             selection, orderby, restrictions,
   168                                             selection, orderby, restrictions,
   164                                             user, ordermethod, visited=visited)
   169                                             user, ordermethod, visited=visited)
   707             assert role
   712             assert role
   708             self._related_cache.pop('%s_%s' % (rtype, role), None)
   713             self._related_cache.pop('%s_%s' % (rtype, role), None)
   709 
   714 
   710     # raw edition utilities ###################################################
   715     # raw edition utilities ###################################################
   711 
   716 
   712     def set_attributes(self, **kwargs):
   717     def set_attributes(self, _cw_unsafe=False, **kwargs):
   713         assert kwargs
   718         assert kwargs
   714         relations = []
   719         relations = []
   715         for key in kwargs:
   720         for key in kwargs:
   716             relations.append('X %s %%(%s)s' % (key, key))
   721             relations.append('X %s %%(%s)s' % (key, key))
   717         # update current local object
   722         # update current local object
   718         self.update(kwargs)
   723         self.update(kwargs)
   719         # and now update the database
   724         # and now update the database
   720         kwargs['x'] = self.eid
   725         kwargs['x'] = self.eid
   721         self.req.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations),
   726         if _cw_unsafe:
   722                          kwargs, 'x')
   727             self.req.unsafe_execute(
       
   728                 'SET %s WHERE X eid %%(x)s' % ','.join(relations), kwargs, 'x')
       
   729         else:
       
   730             self.req.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations),
       
   731                              kwargs, 'x')
   723 
   732 
   724     def delete(self):
   733     def delete(self):
   725         assert self.has_eid(), self.eid
   734         assert self.has_eid(), self.eid
   726         self.req.execute('DELETE %s X WHERE X eid %%(x)s' % self.e_schema,
   735         self.req.execute('DELETE %s X WHERE X eid %%(x)s' % self.e_schema,
   727                          {'x': self.eid})
   736                          {'x': self.eid})
   818             return self
   827             return self
   819         return eobj.get_value(self._attrname)
   828         return eobj.get_value(self._attrname)
   820 
   829 
   821     def __set__(self, eobj, value):
   830     def __set__(self, eobj, value):
   822         eobj[self._attrname] = value
   831         eobj[self._attrname] = value
   823 
   832         if hasattr(eobj, 'edited_attributes'):
       
   833             eobj.edited_attributes.add(self._attrname)
   824 
   834 
   825 class Relation(object):
   835 class Relation(object):
   826     """descriptor that controls schema relation access"""
   836     """descriptor that controls schema relation access"""
   827     _role = None # for pylint
   837     _role = None # for pylint
   828 
   838