Re: [SQLObject] Customizing foreign keys naming style in 0.8 ?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Luper R. <lup...@gm...> - 2007-03-22 19:59:18
|
Oleg Broytmann a écrit : > On Thu, Mar 22, 2007 at 05:22:33PM +0100, Luper Rouch wrote: > >> I tried to use a custom style class, but it does not seem to be >> involved in the ForeignKey name construction. >> > > Please show a test program that triggers the problem with a style. > > Oleg. > Ok I found the answer to my question while trying to explain my problem :-) To customize ForeignKey naming you have to reimplement instanceAttrToIDAttr and instanceIDAttrToAttr in your style class. Here is an example : from sqlobject import * class MyStyle(MixedCaseUnderscoreStyle): def instanceAttrToIDAttr(self, attr): return attr def instanceIDAttrToAttr(self, attr): return attr class Foo(SQLObject): pass class Bar(SQLObject): class sqlmeta: style = MyStyle() fooId = ForeignKey("Foo") if __name__ == "__main__": sqlhub.processConnection = connectionForURI("postgres://localhost/test") Foo.createTable() Bar.createTable() This way Bar.fooId corresponds to bar.foo_id in the database ... Thanks ! Luper Rouch |