On 02/03/2012 12:08 PM, lars van gemerden wrote:
I should probably make the pair method:

def pair(name1, name2):
     p1, p2 = Pairs(name1), Pairs(name2)
     p1.other = p2
     p2.other = p1

On Feb 3, 11:57 am, lars van gemerden<l...@rational-it.com>  wrote:
Hi, I am trying to sote pairs in a table as follows:

#-------------------------------------------------------------------------- 
------------
from elixir import *

metadata.bind = "sqlite:///:memory:"
metadata.bind.echo = False

class Pairs(Entity):
     name = Field(String(50), primary_key = True)
     other = OneToOne('Pairs', inverse = 'other')
You can't have a OneToOne as inverse for a OneToOne, even less for itself. Valid relationship pairs are:

ManyToOne - OneToOne
ManyToOne - OneToMany
ManyToMany - ManyToMany

In your case you want:

class Pairs(Entity):
    name = Field(String(50), primary_key = True)
    other1 = ManyToOne('Pairs', inverse = 'other2')
    other2 = OneToOne('Pairs', inverse = 'other1')

and if your database really only stores pairs, a property might make it more elegant:

    @property
    def other(self):
        return self.other1 if self.other1 is not None else self.other2


As a side note, you probably do not want to use Elixir for a new project, as Elixir is not maintained anymore.

-G.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to