Re: [SQLObject] Re: One-to-one relationships
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Dryice L. <dry...@gm...> - 2005-05-12 13:07:32
|
michelts <mic...@gm...> wrote: > Anyway there is sometimes I think I need a one to one relationship, i > always do something like this: > > class Person(SQLObject): > name =3D StringCol() > def _get_messageBoardEither(self): > """ Return the message board or None """ > s =3D MessageBoard.selectBy(personID=3Dself.id) > return s.count() and s[0] or None > > def _get_messageBoardAlways(self): > """ Returns the message board or instanciate a new message board > with all keys set to default except the foreign key.""" > s =3D MessageBoard.selectBy(personID=3Dself.id) > return s.count() and s[0] or MessageBoard(person=3Dself) Thanks for the reply! I'm in a situation like this sample and I'm planning to make it something like this: class Person(SQLObject): name =3D StringCol() def _get_messageBoard(self): """ Return the message board or None""" s =3D MessageBoard.selectBy(personID=3Dself.id) return s.count() and s[0] or None def _set_messageBoard(self, value): """Set the message, create one if it's not available""" s =3D MessageBoard.selectBy(personID=3Dself.id) m =3D s.count() and s[0] or MessageBoard(person=3Dself) m =3D value _doc_messageBoard =3D """The message board""" As I'm a SQLObject newbie, is this OK?=20=20=20=20 > class MessageBoard(SQLObject): > person =3D ForeignKey('Person', alternateID=3DTrue) > messages =3D MultipleJoin('Message') > > class Message(SQLObject): > board =3D ForeignKey('MessageBoard') > content =3D StringCol() > > This is a kind of a multiple join where I need to set some attributes > (suppose the design of the message board), I don't like to put > internal configuration on person, the person is not a message board > ;), I can create a way to create one to one relationship like creating > a ForeignKey, will this be usefull? What do you on the list think? > What can be the name of the join? Yeah I'd love a one to one relationship join. About the name, how about SingleJoin? Thanks! =2D-=20 Dryice @ http://dryice.3322.org Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/sylvester-response.html |