On Sun, May 12, 2013 at 9:36 AM, Anssi Kääriäinen
<[email protected]>wrote:

> On 12 touko, 02:55, Russell Keith-Magee <[email protected]>
> wrote:
> > To that end - I want to make sure that we're clear about what we're
> talking
> > about here.
> >
> > What is on the table is essentially adding a refresh() call on an object
> > instance that is an API analog of ".get(id=self.id)" (although the
> > implementation will need to do a bit more than that).
>
> Concrete API proposal: Model.refresh() reloads all non-deferred local
> field values (that is, all fields in the current model which have a
> database column). In addition refresh() will make sure that cached
> values dependent of the reloaded values will be cleared. That is, if
> you do foo.refresh(), then when foo.user_id is reloaded foo.user will
> be cleared (assuming the reloaded user_id is different from the
> original value). This is to ensure that next access to foo.user will
> reload the related object, too.
>
> The refresh() method makes sure descriptors are honored, for example
> custom field's to_python() method will be called for refreshed values.
>
> The refresh() method accepts *args, so that one can specify which
> fields to reload. This is useful so that deferred attribute loading
> can use refresh(), and by overriding refresh() it will be possible to
> customize how deferred loading happens.
>
> Deferred field loading is altered to use .refresh().
>
> It might be useful to add model.deferred_fields property. The property
> returns a set of currently deferred fields in the instance. If this
> was available it would be easy to force reload of all currently
> deferred fields, but no reload of other fields. This would also be
> useful for loading all deferred fields when any deferred field is
> accessed. But this can wait for later...
>
> Does the proposal look acceptable?


+1 from me.

The use case for .refresh(*args) being used to pull back multiple deferred
fields is the real deal-maker for me, because it dovetails really nicely
with something Adrian posted about a month ago:

https://groups.google.com/d/msg/django-developers/C3qoHEfeeUg/cwBNV5snQPMJ

It seems to me that ".refresh()" is remarkably close to the "get everything
that was deferred" behaviour that Adrian was looking to add. The fact that
it can also be used to update an instance to the current database state is
a nice side effect in this case.

Russ %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to