On 12/18/08, Gaetan de Menten <[email protected]> wrote: > > On Thu, Dec 18, 2008 at 17:23, Giovanni Marco Dall'Olio > <[email protected]> wrote: > > > Is there a way to create One-To-One auto referential relationships? > > > > I wonder whether it is possible to create something like this: > > > > class Position(Entity): > > next_position = OneToOne('Position') # can be a link to a > > Position_id or None > > previous_position = OneToOne('Position') > > > > actually this example doesn't work, because as explained in the docs, > > every OneToOne relationships needs a OneToMany field on the target > > table. > > > No, OneToOne are exactly like OneToMany, ie they need a *ManyToOne* on > the target table, because a ManyToOne creates a column with a > ForeignKey constraint, while a OneToOne does not. So your example > should work fine if you change it this way: > > class Position(Entity): > next_position = ManyToOne('Position') > previous_position = OneToOne('Position')
yes, it works. Thanks for the quick answer :) > -- > Gaƫtan de Menten > http://openhex.org > > > > -- My blog on bioinformatics (now in English): http://bioinfoblog.it --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SQLElixir" 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/sqlelixir?hl=en -~----------~----~----~----~------~----~------~--~---
