Just a wild guess, but have you tried making your association table like:
#association table
user_group_table = Table('t_user_group', metadata,
Column('user_id', Integer, ForeignKey('t_user.c.user_id',
onupdate="CASCADE", ondelete="CASCADE")),
Column('group_id', Integer, ForeignKey('t_group.c.group_id',
onupdate="CASCADE", ondelete="CASCADE")),
Column('project_id', Integer, ForeignKey('t_project.c.project_id',
onupdate="CASCADE", ondelete="CASCADE"))
)
My understanding is that ".c." means "column" so it might need to be
"t_user.c.user_id" (from table t_user, get the column user_id)
I don't have too much hope with that, but you never know...
2011/2/16 Abdul Gaffar <[email protected]>:
>
>
> --
> 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.
>
>
>
> ---------- Mensaje reenviado ----------
> From: Abdul Gaffar <[email protected]>
> To: [email protected]
> Date: Wed, 16 Feb 2011 16:28:47 +0530
> Subject: Need Urgent Help - SQLAlchemy Relation
> 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
"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.