From: Mike Bayer Date: Sun, 26 Mar 2006 23:51:13 +0000 (+0000) Subject: added always_refresh flag. when the mapper loads rows, it will pull objects from... X-Git-Tag: rel_0_1_5~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4e00af9e47bf28cdc9ab9af85514e76c3063a67;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added always_refresh flag. when the mapper loads rows, it will pull objects from the identity map normally, but always blows away their attributes and replaces with those from the database, including changes --- diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py index 8ff28cf56d..ed07983e44 100644 --- a/lib/sqlalchemy/mapping/mapper.py +++ b/lib/sqlalchemy/mapping/mapper.py @@ -39,6 +39,7 @@ class Mapper(object): extension = None, order_by = False, allow_column_override = False, + always_refresh = False, **kwargs): if primarytable is not None: @@ -52,6 +53,7 @@ class Mapper(object): self.is_primary = is_primary self.order_by = order_by self._options = {} + self.always_refresh = always_refresh if not issubclass(class_, object): raise ArgumentError("Class '%s' is not a new-style class" % class_.__name__) @@ -308,7 +310,7 @@ class Mapper(object): return self._get(key, ident) def _get(self, key, ident=None, reload=False): - if not reload: + if not reload and not self.always_refresh: try: return objectstore.get_session()._get(key) except KeyError: @@ -815,6 +817,8 @@ class Mapper(object): # look in main identity map. if its there, we dont do anything to it, # including modifying any of its related items lists, as its already # been exposed to being modified by the application. + + populate_existing = populate_existing or self.always_refresh identitykey = self._identity_key(row) sess = objectstore.get_session() if sess.has_key(identitykey):