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:
Cc:

Description

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,
                 joinColumn='child_id',
                 otherColumn='parent_id',
                 addRemoveName="Parent")
  Children = RelatedJoin('Atom', intermediateTable=AtomChildren,
                 joinColumn='parent_id',
                 otherColumn='child_id',
                 addRemoveName="Child")

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

Hey

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.

-Rob

Note: See TracTickets for help on using tickets.