Hi everyone,

I just joined the list and must congratulate Kevin and all of the devs
for Turbogears! It has brought back the funness of coding a web site!

I thought I might share a quick fix to catwalk when dealing with
SQLObject model classes wich are named using camel case. Catwalk fails
to get the correct column names for foreign keys which
refer to a camel-cased object. I'm using 0.9a8 so apologies if it's
fixed in the trunk...

Here's an example:

model.py:

class BlogEntry(SQLObject):
    subject = UnicodeCol(notNone=True)
    body = UnicodeCol(notNone=True)
    comments = MultipleJoin("Comment")

class Comment(SQLObject):
    subject = UnicodeCol(notNone=True)
    body = UnicodeCol(notNone=True)
    blogEntry = ForeignKey("BlogEntry")


In the above example tg-adimin sql create will create a table called:
blog_entry
comments

In catwalk, the foreign key column name referencing blog_entry (thus
blog_entry_id) is not obtained correctly. It gets blog_id instead, and
catwalk just sits there and does nothing when you browse the blogEntry
via the comment structure.

So here is the fix:

+++ TurboGears-0.9a8-py2.4.egg/turbogears/toolbox/catwalk/browse.py
2006-08-04 18:04:50.000000000 +0900
@@ -192,7 +192,7 @@
         return fk_values

     def join_foreign_key(self,column):
-        foreign_key = '%sID'% column.joinColumn.split('_')[0]
+        foreign_key = '%sID' %
'_'.join(column.joinColumn.split('_')[:-1])
         return getattr(column.otherClass.q,foreign_key)

     def column_label_options(self,column):

This patch will make catwalk get the correct 'blog_entry_id' instead of
'blog_id' as the column name.
Not sure if it is ticket-worthy, but if anybody is having the same
problem, try this. 

Cheers
Vik


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to