thank you,

this bug is fixed in r5893.


kris wrote:
>
> I am getting a new error with 0.5.3, I've tried to work around it but
> can't seem to find the
> right magic.
>
> Can't determine relation direction for relationship 'Taggable.owner' -
> foreign key columns are present in both the parent and the child's
> mapped tables.  Specify 'foreign_keys' argument.
>
> An example code is below (works in 0.5.2, breaks in 0.5.3)
>
>
> Changing the 'owner' property to work with the user table removes the
> error,
>  but the owner is never actually set in the DB...
>
>     #'owner' : relation (User,
>     #                   primaryjoin=(taggable.c.owner_id ==
> users.c.id),
>     #                    foreign_keys=[users.c.id],
>     #                    uselist=False,
>     #                    ),
>
>
>
>
>
>
> from sqlalchemy import Table, Column, Integer, String, MetaData,
> ForeignKey, UnicodeText
> from sqlalchemy.orm import mapper,relation, sessionmaker
>
> metadata = MetaData()
>
> taggable = Table('taggable', metadata,
>                  Column('id', Integer, primary_key=True),
>                  Column('type', UnicodeText),
>                  Column('owner_id', Integer, ForeignKey
> ('taggable.id')),
>                  )
> users = Table ('users', metadata,
>                Column('id', Integer, ForeignKey('taggable.id'),
>                       primary_key=True),
>                Column('user_name', UnicodeText),
>                )
>
> tags = Table ('tags', metadata,
>               Column('id',  Integer, ForeignKey('taggable.id'),
> primary_key=True),
>               Column('parent_id', Integer, ForeignKey('taggable.id')),
>               Column('tag', UnicodeText)
>               )
>
>
> images= Table ('images', metadata,
>                Column('id', Integer, ForeignKey('taggable.id'),
> primary_key=True),
>                Column('src', UnicodeText),
>                )
>
>
>
> class Taggable(object):
>     pass
> class Image(Taggable):
>     def __init__(self):
>         self.type="image"
>
> class Tag(Taggable):
>     def __init__(self, v = None):
>         self.type="tag"
>         self.tag = v
>
> class User(Taggable):
>     def __init__(self):
>         self.type="user"
>
>
>
> mapper( Taggable, taggable, properties = {
>     'owner' : relation (User,
>                        primaryjoin=(taggable.c.owner_id ==
> taggable.c.id),
> #                        foreign_keys=[taggable.c.id],
>                         uselist=False,
>                         ),
>
>
>     'tags' : relation(Tag, lazy=True, cascade="all, delete-orphan",
>                       primaryjoin= (tags.c.parent_id==taggable.c.id))
>     }
> )
>
> mapper(Image, images, inherits=Taggable,
>        inherit_condition=(images.c.id == taggable.c.id),
>        )
> mapper(Tag, tags, inherits=Taggable,
>        inherit_condition=(tags.c.id == taggable.c.id),
> )
> mapper(User, users, inherits=Taggable,
>        inherit_condition=(users.c.id == taggable.c.id),
>        )
>
>
>
>
> from sqlalchemy import create_engine
> engine = create_engine('sqlite:///:memory:', echo=True)
>
>
>
> metadata.create_all(engine)
>
> Session = sessionmaker(bind=engine)
> session = Session()
>
> k = User()
> k.owner = k
> k.user_name ="k"
> session.add(k)
>
> i = Image()
> i.owner = k
> i.src = "someplace"
> session.add(i)
>
> tags = [ Tag("t%d" % x ) for x in range(2) ]
> for t in tags:
>     t.owner = k
> i.tags = tags
>
> session.flush()
> session.commit()
> #print k.id
> #print i.id, i.owner_id
>
> #print "TAGS", i.tags
>
> i = session.query(Image).all() [0]
> print "IMAGE", i.id, i.owner
>
> i.tags = []
> session.commit()
>
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to