Can I do a compound fetch for a one-to-one relationship in a single
statement?
Suppose I have a model like this:
model.py
...
class Resource(SQLObject):
  name           = UnicodeCol(alternateID=True, length=30)
  completionTime = DateTimeCol()

class Location(SQLObject):
  name           = UnicodeCol(alternateID=True, length=256)
  lat            = DecimalCol(size=9, precision=6)
  lon            = DecimalCol(size=9, precision=6)
  res_id     = ForeignKey('Resource')
...
I am tempted to write some code like this in controllers.py (but it
looks sucky to me, so I know it MUST be wrong :-)
class Root(controllers.RootController):
"..."
    @expose()
    @expose("json")
    def resourcelist(self):
      resultSet = []
      resourceList = [[resource.id, resource.name,
resource.completionTime]
         for resource in Resource.select(orderBy=Resource.q.name)]
      for r in resourceList:
        res_id = r[0]
        locs = [[loc.name, loc.lat, loc.lon] for loc in
Location.select(Location.q.id==res_id)]
        for l in locs:
          resultSet.append([r[1],l[0], str(l[1]), str(l[2]), r[2] ])
      return dict(resources=resultSet)

What's the sporty way to do this (or is the answer to add attributes
to the model?
Thanks. I love this group BTW
Dana


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to