hi,

what's wrong with the following mapping ?

TYPE_DEFAULT = 1

class BaseFriend(DeclarativeBase):
    
    __tablename__ = 'friends'
    __table_args__ = {'mysql_engine': 'InnoDB',
                      'mysql_charset': 'utf8'}
    
    type = Column(SmallInteger, primary_key=True)

    user_id = Column(None, ForeignKey('users.id', ondelete='CASCADE'), 
primary_key=True)
    
    friend_id = Column(None, ForeignKey('users.id', ondelete='CASCADE'))

    friend_external_id = Column(String(100), primary_key=True)

    __mapper_args__ = dict(
        polymorphic_on=type,
        polymorphic_identity=TYPE_DEFAULT,
    )

TYPE_FACEBOOK = 2

class FacebookFriend(BaseFriend):
    
    __mapper_args__ = dict(
        polymorphic_identity=TYPE_FACEBOOK,
    )

User.facebook_friends = relationship(FacebookFriend,
    lazy=False,
    primaryjoin=FacebookFriend.user_id==User.id,
    backref='user'
)

when i try to session.query(User).first() i'm getting:

New instance <FacebookFriend at 0x5b79850> with identity key (<class 
'...Friend.BaseFriend'>, (2, 75L, u'100001288076626')) conflicts with 
persistent instance <FacebookFriend at 0x5c59710>

i've tried to define the relationship on both sides with the same results

thanks

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/k_QD0fDYRJ0J.
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