236 else: |
236 else: |
237 visited.add(eschema.type) |
237 visited.add(eschema.type) |
238 _fetchattrs = [] |
238 _fetchattrs = [] |
239 for attr in fetchattrs: |
239 for attr in fetchattrs: |
240 try: |
240 try: |
241 rschema = eschema.subject_relation(attr) |
241 rschema = eschema.subjrels[attr] |
242 except KeyError: |
242 except KeyError: |
243 cls.warning('skipping fetch_attr %s defined in %s (not found in schema)', |
243 cls.warning('skipping fetch_attr %s defined in %s (not found in schema)', |
244 attr, cls.id) |
244 attr, cls.id) |
245 continue |
245 continue |
246 if not user.matching_groups(rschema.get_groups('read')): |
246 if not user.matching_groups(rschema.get_groups('read')): |
247 continue |
247 continue |
248 var = varmaker.next() |
248 var = varmaker.next() |
249 selection.append(var) |
249 selection.append(var) |
250 restriction = '%s %s %s' % (mainvar, attr, var) |
250 restriction = '%s %s %s' % (mainvar, attr, var) |
251 restrictions.append(restriction) |
251 restrictions.append(restriction) |
252 if not rschema.is_final(): |
252 if not rschema.final: |
253 # XXX this does not handle several destination types |
253 # XXX this does not handle several destination types |
254 desttype = rschema.objects(eschema.type)[0] |
254 desttype = rschema.objects(eschema.type)[0] |
255 card = rschema.rproperty(eschema, desttype, 'cardinality')[0] |
255 card = rschema.rproperty(eschema, desttype, 'cardinality')[0] |
256 if card not in '?1': |
256 if card not in '?1': |
257 cls.warning('bad relation %s specified in fetch attrs for %s', |
257 cls.warning('bad relation %s specified in fetch attrs for %s', |
288 if cls.rest_attr: |
288 if cls.rest_attr: |
289 mainattr = cls.rest_attr |
289 mainattr = cls.rest_attr |
290 needcheck = not cls.e_schema.has_unique_values(mainattr) |
290 needcheck = not cls.e_schema.has_unique_values(mainattr) |
291 else: |
291 else: |
292 for rschema in cls.e_schema.subject_relations(): |
292 for rschema in cls.e_schema.subject_relations(): |
293 if rschema.is_final() and rschema != 'eid' and cls.e_schema.has_unique_values(rschema): |
293 if rschema.final and rschema != 'eid' and cls.e_schema.has_unique_values(rschema): |
294 mainattr = str(rschema) |
294 mainattr = str(rschema) |
295 needcheck = False |
295 needcheck = False |
296 break |
296 break |
297 if mainattr == 'eid': |
297 if mainattr == 'eid': |
298 needcheck = False |
298 needcheck = False |
485 Overrides this if you want another behaviour |
485 Overrides this if you want another behaviour |
486 """ |
486 """ |
487 assert self.has_eid() |
487 assert self.has_eid() |
488 execute = self.req.execute |
488 execute = self.req.execute |
489 for rschema in self.e_schema.subject_relations(): |
489 for rschema in self.e_schema.subject_relations(): |
490 if rschema.is_final() or rschema.meta: |
490 if rschema.final or rschema.meta: |
491 continue |
491 continue |
492 # skip already defined relations |
492 # skip already defined relations |
493 if getattr(self, rschema.type): |
493 if getattr(self, rschema.type): |
494 continue |
494 continue |
495 if rschema.type in self.skip_copy_for: |
495 if rschema.type in self.skip_copy_for: |
533 return self.req.decorate_rset(rset) |
533 return self.req.decorate_rset(rset) |
534 |
534 |
535 def to_complete_relations(self): |
535 def to_complete_relations(self): |
536 """by default complete final relations to when calling .complete()""" |
536 """by default complete final relations to when calling .complete()""" |
537 for rschema in self.e_schema.subject_relations(): |
537 for rschema in self.e_schema.subject_relations(): |
538 if rschema.is_final(): |
538 if rschema.final: |
539 continue |
539 continue |
540 if len(rschema.objects(self.e_schema)) > 1: |
540 if len(rschema.objects(self.e_schema)) > 1: |
541 # ambigous relations, the querier doesn't handle |
541 # ambigous relations, the querier doesn't handle |
542 # outer join correctly in this case |
542 # outer join correctly in this case |
543 continue |
543 continue |