Hi Jason. You are correct, Package.objects.all() does the job partially, but I forget to mention (sorry) that what I want is all coments from a specified package.
WHERE Package.name = 'some_package_name' So using Packages.objects.all() does not retrieve, or dos not select, all the comments from that package. I know I can filter by name, package_list = Package.objects.filter(name='something') but that doesn't give me the comments for that package, because there's no relation between those tables. The bad side of this approach is that I cannot change the ERM for this database. I'm guessing that the only option is using raw queries. Ricardo F. Teixeira On Mar 18, 4:52 pm, Jason Culverhouse <ja...@mischievous.org> wrote: > On Mar 18, 2011, at 6:38 AM, Ricardo F. Teixeira wrote: > > > Hi everyone! > > > Without using raw SQL queries how can I make multiple joins using this > > model? > > Do a search for "django select_related reverse one to many" for some > alternatives > > > > > > > I'm trying to get something like this: > > > SELECT Package.package, Release.release, Release.version, > > ContribComment.* > > FROM ContribComment > > INNER JOIN Contrib > > ON Contrib.id = ContribComment.fk_contrib_id > > INNER JOIN ContribRelease > > ON ContribRelease.fk_contrib = Contrib.id > > INNER JOIN Release > > ON Release.id = ContribRelease.id > > INNER JOIN Package > > ON Package.id = Release.fk_package > > > Is that possible to anchive something like this without using raw SQL > > queries? > > I'm asking that because I can't find any example with multiple inner > > joins that is similar to my model. > > What you want work is: > Package.objects.select_related() > > But since the ORM will only follow 'forward' ForeignKey references, > the result will be the same as: > Package.objects.all() > > You can get close with > ContribRelease.objects.select_related() > > which will inner join everything except ContribComment since there is no > "forward" ForeignKey reference > > seehttp://docs.djangoproject.com/en/dev/ref/models/querysets/#select-rel... > > > > > > > class ContribComment(models.Model): > > fk_contrib_id = models.ForeignKey(Contrib) > > subject = models.TextField() > > text = models.TextField() > > ratings = models.IntegerField() > > > class Contrib(models.Model): > > username = models.TextField() > > city = models.TextField() > > > class ContribRelease(models.Model): > > fk_contrib = models.ForeignKey(Contrib) > > fk_release = models.ForeignKey(Release) > > > class Release(models.Model): > > fk_package = models.ForeignKey(Package) > > release = models.TextField() > > version = models.TextField() > > distribution = models.TextField() > > arch = models.TextField() > > summary = models.TextField() > > description = models.TextField() > > > class Package(models.Model): > > name = models.TextField(unique=True) > > homepage = models.TextField() > > snapshot = models.TextField() > > > Thanks, > > > Ricardo F. Teixeira > > Jason -- 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.