Ok, I translated my example to SQLAlchemy:

--------------------------------------

from sqlalchemy import *
from sqlalchemy.orm import mapper, relation, sessionmaker

engine = create_engine('sqlite:///:memory:', echo=True)
metadata = MetaData()

class A(object):
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return '<A: %r>' % self.name

class B(A):
    def __init__(self, name):
        super(B, self).__init__(name)

    def __repr__(self):
        return '<B: %r>' % self.name

class C(A):
    def __init__(self, name):
        super(C, self).__init__(name)

    def __repr__(self):
        return '<C: %r>' % self.name

_a_table = Table('a', metadata,
    Column('id', Integer, primary_key=True),
    Column('name', String),
    Column('type', String(30), nullable=False)
)

_b_table = Table('b', metadata,
    Column('id', Integer, ForeignKey('a.id'), primary_key=True)
)

_c_table = Table('c', metadata,
    Column('id', Integer, ForeignKey('a.id'), primary_key=True),
    Column('b_id', Integer, ForeignKey('b.id'))
)

mapper(A, _a_table, polymorphic_on=_a_table.c.type,
polymorphic_identity='a')
mapper(B, _b_table, inherits=A, polymorphic_identity='b', \
       properties={'many_c': relation(C, backref='some_b', \
                   primaryjoin=_b_table.c.id==_c_table.c.b_id)})
mapper(C, _c_table, inherits=A, polymorphic_identity='c')

metadata.create_all(engine)

Session = sessionmaker(engine)
session = Session()

b = B(name='b')
session.save(b)

c1 = C(name='c1')
c2 = C(name='c2')

b.many_c.append(c1)
b.many_c.append(c2)

session.save(b)

print b
print b.many_c

for c in b.many_c:
    print c.some_b

-----------------------------

I had to define the primaryjoin keyword to get this working.

So, how to use that with Elixir? How do I achieve the same?


Regards,
Ben

On Aug 29, 8:53 pm, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> On 8/29/07, Ben Schwarze <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi all,
>
> > I'm having a problem in using inheritance in combination with multiple
> > ForeignKeys.
>
> > --------------------------------------------
>
> > from elixir import *
>
> > metadata.bind = 'sqlite:///mydbname.sqlite'
>
> > class A(Entity):
> >     has_field('name', String)
> >     using_options(shortnames=True, inheritance='multi',
> > polymorphic=True)
>
> > class B(A):
> >     has_many('many_c', of_kind='C', inverse='some_b')
> >     using_options(shortnames=True, inheritance='multi',
> > polymorphic=True)
>
> > class C(A):
> >     belongs_to('some_b', of_kind='B', inverse='many_c')
> >     using_options(shortnames=True, inheritance='multi',
> > polymorphic=True)
>
> > create_all()
>
> > --------------------------------------
>
> > Executing this example it gives me the following error:
>
> > sqlalchemy.exceptions.ArgumentError: Can't determine join between
> > 'Join object on a b' and 'c'; tables have more than one foreign key
> > constraint relationship between them. Please specify the 'onclause' of
> > this join explicitly.
>
> > How can this problem be solved?
>
> This is obviously a bug in Elixir or SQLAlchemy. Unfortunately I have
> no time at the moment to track it down. If you want to help fixing it,
> the first step is to translate your example into raw SQLAlchemy code
> and see if that works or not.
>
> If it doesn't work, please report it to the SQLAlchemy's list.
> Otherwise, report back here, along with your SQLAlchemy code so that I
> can figure out what is Elixir doing differently.
> --
> Gaƫtan de Mentenhttp://openhex.org


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

Reply via email to