Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #787 (closed defect: invalid)

Opened 13 years ago

Last modified 12 years ago

SQLObject missing table.q.field mappings for ForeignKey columns.

Reported by: matt.bevan@… Owned by: anonymous
Priority: normal Milestone:
Component: SQLObject Version: 0.9a3
Severity: normal Keywords:


Why does every field in a table have a .q. mapping (to get the SQL name of a field) except a ForeignKey?? They definitely have a SQL representation, an I really do not want to hard-code the column names. I -like- being flexible.

(Cross-posted to the development forum.)

Take the following example:

class AtomChildren(SQLObject):
  parent = ForeignKey('Atom')
  child  = ForeignKey('Atom')
  sort   = IntCol(default = 0)

class Atom(InheritableSQLObject):
  Name     = UnicodeCol(length=255)
  Parents  = RelatedJoin('Atom', intermediateTable=AtomChildren,
  Children = RelatedJoin('Atom', intermediateTable=AtomChildren,

To do a custom query requires:

result = model.Atom.select(
           AND(model.Atom.q.Name == 'default',
               "atom_children.child=%s" % model.Atom.q.id,
               "atom_children.parent = %d" % node.id))

When it really should be:

result = model.Atom.select(
           AND(model.Atom.q.Name == 'default',
               model.AtomChildren.q.child == model.Atom.q.id,
               model.AtomChildren.q.parent == node.id))

Looking through the code for SQLObject I can't easily see why there would be a difference.

  • Matthew

Change History

comment:1 Changed 13 years ago by godoy

  • Status changed from new to closed
  • Resolution set to invalid

Answered on the ML:

[TurboGears] Re: Lack of table.q.field mappings for ForeignKey? columns in SQLObject. From: Robin Haswell <rob@…> To: turbogears@… Date: Tue Apr 25 19:33:19 2006


Quickie post because I gotta go to bed. This bit me a few nights ago, quick answer:

class Foo(SQLObject):

bar = ForeignKey?("Baz")

Column is Foo.q.bazID

You can do Foo.select(AND(Foo.q.bazID == Baz.q.id, Baz.q.something == "whatever"))

I agree. SO is rubbish in this respect.

Night night.


Note: See TracTickets for help on using tickets.