Say i have the following Users model-


class Users(Base):
    __tablename__='users'
    id=Column(Integer, primary=True)
    friends=relationship(
        'Users',
        secondary='friend_associations',
        primaryjoin='and_(FriendAssociations.user_id==Users.id,'
            'FriendAssociations.pending==False)',
        secondaryjoin='and_(FriendAssociations.friend_id==Users.id,'
            'FriendAssociations.pending==False)',
        uselist=True,
    )


And the FriendAssociations model is-


class FriendAssociations(Base):
    __tablename__='friend_associations'
    id=Column(Integer, primary=True)
    user_id=Column(ForeignKey('Users.id'), nullable=False)
    friend_id=Column(ForeignKey('Users.id'), nullable=False)
    pending=Column(Boolean, default=True)
    __table_args__ = (UniqueConstraint(
        'user_id','friend_id', name='uq_user_friend_id_pair'
    ),)


The target was, user A sends a friend request to user B. Until user B 
accepts the request, the request stays as pending. When B accepts the 
request, pending is False and one more friend_associations entry is created 
on user B to state that user A is friend of user B and vice versa. The 
problem is, i can do these things, but when i want to remove a user entry, 
the database(i am using PostgreSQL) throws up error saying 
friend_associations depends on the user(because the association entry isn't 
deleted). As a result i can't delete any user entry.

So -

   1. Is my solution to the problem correct?
   2. If not, what should i do to correct it?
   3. Please give basic query examples like adding, deleting friends and 
   user entries with such solution or mine.

Thanks in advance.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to