ming extensions before_insert not creating new objects

52 Views Asked by At

I am trying to insert a new Role or Roles that are required for a new User that is being created. But for some reason the roles are not created. Any idea why the role is not created but the User is? The session shows the Role in

class UserExtension(MapperExtension):

  def before_insert(self, obj, status, session):
    role_user_id = Role(context='user', context_id=obj._id)
    obj.role_ids.append(role_user_id._id)

class User(BaseMappedClass):

  class __mongometa__:
    session = DBSession
    name = 'users'
    unique_indexes = [('email',)]
    extensions = [UserExtension, ModifiedExtension]

I tried using session.save(role_user_id) but still no new document.

1

There are 1 best solutions below

0
On
session.flush(role_user_id) 

works.