On 13/06/2006, at 4:55, Charles Duffy wrote:

>
> Jorge Vargas wrote:
>> you can set up a call on the bottom of your model.py to make that  
>> call.
>> http://www.sqlobject.org/SQLObject.html#creating-and-dropping-tables
>> although that will eliminate all middle tables
>
> Thanks for the suggestion!
>
> I actually ended up doing the following at the end of model.py:
>
> classNames = set(locals())
> for clsName in list(classNames):
>   cls = locals()[clsName]
>   if (isinstance(cls, type) and issubclass(cls, SQLObject)
>       and cls is not SQLObject
>       and cls is not InheritableSQLObject):
>     if hasattr(cls, 'createTableArgs'):
>       cls.createTable(ifNotExists=True, **cls.createTableArgs)
>     else:
>       cls.createTable(ifNotExists=True)
>   else:
>     classNames.remove(clsName)
>
>
> That lets me set createTableArgs for a given class to something like {
> 'createJoinTables': False } while not changing the defaults more than
> need be.

You can also try something like:

---- In model_helpers.py -----

class SORelatedJoinNoIT(SORelatedJoin):
     """Base class for a RelatedJoin without automatic intermediate  
table.
     """
     def hasIntermediateTable(self):
         return False

class RelatedJoinNoIT(RelatedJoin):
     """A RelatedJoin without automatic intermediate table.
     """
     baseClass = SORelatedJoinNoIT

---- In model.py ----

from sqlobject import *
RelatedJoinOrig = RelatedJoin
from model_helpers import RelatedJoinNoIT as RelatedJoin

Now all your related joins won't generate an intermediate table (of  
course, you can avoid the name mangling if you prefer an automatic  
intermediate table for most of your joins, then just use  
RelatedJoinNoIT for those special joins you provide an intermediate  
table for).

The intermediate table auto-generated name concats both tables' names  
in alphabetical order, so your "manually" created tables should  
follow this convention (ArticleImage, BarFoo, etc...).
Foreign key column names are the name of the joined table + id, all  
lowercase: article_id, image_id, etc...

HTH,
Alberto

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