On 20 Paź, 08:37, "Michael P. Jung" <mpj...@terreon.de> wrote:
> > I was unclear, but SQL should explain what I want to do - select
> > all ObjectRevision-s that are latest in Object-s that they belong to.
> > Moreover, I want to do this in with one ORM query, without resorting
> > to SQL or splitting the query too much.
>
> I'd go for a denormalized database:
>
> class Foo(models.Model):
> latest_revision = models.OneToOneField('FooRevision',
> related_name='latest_revision_for')
> ...
>
> class FooRevision(models.Model):
> foo = models.FogeignKey(Foo)
> ...
>
> That way you can easily query Foo.objects.all().select_related() and be
> done. It'll be faster than your rather complex DB query and can be
> handled in the Django ORM. I'd say it's a win win situation.
>
I'm aware of this solution, in fact I was using it.
Unfortunately I had problems with deleting objects with this circular
dependency,
but maybe I was overlooking something (db we're using is MySQL 5).
Anyway, my case is much more complicated so I would have to
denormalize
more than just one model. Because of that, of because VIEWs + fake
models
are quick enough for what I'm doing (and has enough speed reserve for
the future),
I decided to go this path.
--
Tomasz Zielinski,
http://pyconsultant.eu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---