Unfortunately, I'm not able to provide any help with this problem. This is a SQLAlchemy issue, and one that's outside of my knowledge of working with SA. I have to suggest asking on the SA lists and/or IRC channel for help with this.
On Wed, Feb 16, 2011 at 5:58 AM, Abdul Gaffar <[email protected]>wrote: > Hi all, > > I need urgent help on SQLAlchemy relations. I have three classes User, > Group, Project and association user_group_table. > > > > class User(DeclarativeBase): > __tablename__ = 't_user' > user_id = Column(Integer, autoincrement=True, primary_key=True) > user_name = Column(Unicode(32), unique=True, nullable=False) > email_address = Column(Unicode(320), unique=True, nullable=False, > info={'rum': {'field':'Email'}}) > > def __repr__(self): > return ('<User: user_name=%r, email=%r>' % ( > self.user_name, > self.email_address)).encode('utf-8') > > def __unicode__(self): > return self.user_name > > > > class Group(DeclarativeBase): > __tablename__ = 't_group' > group_id = Column(Integer, autoincrement=True, primary_key=True) > group_name = Column(Unicode(16), unique=True) > > users=relation('User', secondary=user_group_table,backref='groups') > > def __repr__(self): > return ('<Group: name=%s>' % self.group_name).encode('utf-8') > > def __unicode__(self): > return self.group_name > > > class Project(DeclarativeBase): > __tablename__ = 't_project' > > project_id = Column(Integer, autoincrement=True, primary_key=True) > project_name = Column(Unicode(80), unique=True, nullable=False) > > project=relation('Group', secondary=auth.user_group_table, > backref='Project') > > def __repr__(self): > return "<Project('%s')> % self.project_name > > > #association table > user_group_table = Table('t_user_group', metadata, > Column('user_id', Integer, ForeignKey('t_user.user_id', > onupdate="CASCADE", ondelete="CASCADE")), > Column('group_id', Integer, ForeignKey('t_group.group_id', > onupdate="CASCADE", ondelete="CASCADE")), > Column('project_id', Integer, ForeignKey('t_project.project_id', > onupdate="CASCADE", ondelete="CASCADE")) > ) > > > I am unable to insert the records into association table.... > below is the code snippet for insertion > > user = DBSession.query(User).filter(User.user_name == kw['PM']).one() > group = DBSession.query(Group).filter(Group.group_name == 'pm').one() > project = DBSession.query(Project).\ filter(Project.project_id > == kw['project_id']).one() > > > group.users.append(user) > project.project.append(group) > DBSession.flush() > transaction.commit() > > > Please help me ASAP. > > > Thanx in advance > > -- > You received this message because you are subscribed to the Google Groups > "TurboGears" 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/turbogears?hl=en. > > -- Michael J. Pedersen My IM IDs: Jabber/[email protected], ICQ/103345809, AIM/pedermj022171 Yahoo/pedermj2002, MSN/[email protected] -- You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en.

