I've posted the following question on the Elixir group and they sent
me here.
My setup
##
# Tables
##
roles = Table('roles', meta,
Column('id', Integer, primary_key=True),
Column('name', String(25))
)
users = Table('users', meta,
Column('id', Integer, primary_key=True),
Column('username', String(125)),
Column('password', String(125)),
....
)
users_roles = Table('users_roles', meta,
Column('user_id', Integer, primary_key=True),
Column('role_id', Integer, primary_key=True),
....
ForeignKeyConstraint(['user_id'], ['users.id']),
ForeignKeyConstraint(['role_id'], ['roles.id'])
)
##
# Elixir models
##
class UserRole(Entity):
using_options(tablename='users_roles', autoload=True)
user = ManyToOne('User', colname='user_id')
role = ManyToOne('Role', colname='role_id')
class Role(Entity):
using_options(tablename='roles', autoload=True)
users_roles = OneToMany('UserRole')
users = AssociationProxy('users_roles', 'user')
class User(Entity):
using_options(tablename='users', autoload=True)
users_roles = OneToMany('UserRole')
roles = AssociationProxy('users_roles', 'role')
This setup works fine for reading but not for updating or deleting.
I was able to then get the append method working via the following
def _create_ur_by_role(role):
return UserRole(role=role)
in class User:
roles = AssociationProxy('users_roles', 'role',
creator=_create_ur_by_role)
I am still unable to delete roles. Example:
me.roles.pop() < -- works fine
session.flush()
results in...
AssertionError: Dependency rule tried to blank-out primary key column
'users_roles.user_id'
I have tried adding ondelete='cascade' to the UserRole model. This
caused no change.
Any help will be greatly appreciated
-brad
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---