Hello,

I have a system to manage users in my application, but I'm getting
some troubles with it.

Every user has to belong to a group of users. One user can only be in
one group.

I have those tables (inheriting from rdb.Model is basically the same
thing than using sqlalchemy's declarative model)

class User(rdb.Model):
        """Represents the user"""
        rdb.metadata(metadata)
        rdb.tablename("users")

        id = Column("id", Integer, primary_key=True)
        name = Column("name", String(50))
        ....

        userGroup = relationship("UserGroup", uselist=False)
        .....

class UserGroup(rdb.Model):
        """Represents a group of users with the same features"""
        rdb.metadata(metadata)
        rdb.tablename("user_groups")

        id = Column("id", Integer, primary_key=True)
        title = Column("title", String(50))

        users = relationship("User", order_by="User.name", cascade="all,
delete, delete-orphan", backref="user_groups")
        ....

I have a script which migrate users from a pre-existing Zope DB
(object-oriented):

def migrateUsers():
        """Migrate all the users to the database"""
        session = rdb.Session()
        rScreens = session.query(Screen).all()
        rUserGroups = session.query(UserGroup).all()
        .....

        for oldUser in grok.getSite()['Users'].values():
                user = User()
                ......
                for newGroup in rUserGroups:
                        if newGroup.title == "superadmins":
                                newGroup.users.append(user)
                ......

        return

When I execute the script, the user_groups are properly created and
the users are properly added to the user_groups they should belong to,
but I get empty "group" entries in the database, and I don't know why

I have made some tests, and I've realized that I get an empty entry
(an empty user_group) every time I try to add a user to a user_group,
but I don't know what is causing this behavior.

Any hint will be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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