Project

General

Profile

Bug #928

Resolving relations to VersionedRecord classes happens on Primary Key only

Added by Elmer de Looff over 12 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Elmer de Looff
Category:
Model
Target version:
Start date:
2012-08-23
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

Currently, foreign relations to the VersionedRecord class are resolved using the FromPrimary method. This means that a specific (possibly outdated) version of the appropriate record is returned. In most situations, the reference is actually to the record in general, and not to a specific version of that record.

That is to say, the default loading method for VersionedRecord classes should be FromIdentifier.

Ideally, the specific method used for loading should be specified by the designer of the various relations, as there exist various situations where the specific version needs linking instead.

Associated revisions

Revision 289:996a08a1b2c2 (diff)
Added by Elmer de Looff over 12 years ago

Added (failing) test for uWeb model to confirm issue #928.

Revision 290:e811dcd32282 (diff)
Added by Elmer de Looff over 12 years ago

Retrieving a foreign relation that is a VersionedRecord now automatically (by default) uses FromIdentifier. This behaviour can be changed by either defining the _LOAD_METHOD class variable, which changes the global load behaviour, or by provinding a dictionary to the _FOREIGN_RELATIONS mapping, where the class name is a dictionary with 'class' and 'loader' keys. The latter being a string naming the loader method for foreign relations. This resolves #928.

History

#1 Updated by Elmer de Looff over 12 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 70

Applied in changeset e811dcd32282.

#2 Updated by Elmer de Looff over 12 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 70 to 100

VersionedRecord now retrieves requested foreign related records using FromIdentifier. This behaviour can be adjusted both on a per-class level, and a per-relation level:

Changing the load method for the entire class:

from uweb import model

class Customer(model.VersionedRecord):
  """Versioned customer class that is loaded as specific version by default""" 
  _LOAD_METHOD = 'FromPrimary'

Changing the load method for a single relation:

from uweb import model

class Customer(model.VersionedRecord):
  """Versioned customer class""" 

class Invoice(model.Record):
  """Invoice class, related customers are of a fixed version""" 
  _FOREIGN_RELATIONS = {'customer': {'class': Customer, 'loader': 'FromPrimary'}}

Also available in: Atom PDF