Skip to content

Add transaction feature to ORM #110

@ghost

Description

For creating user i need to do this actions (insert to users, roles_users and user_profile (first_name, last_name data and some) tables (this is method from Model_User):

public function createUser($userData, $userProfileData, $userRoles = array(Model_Role::ROLE_LOGIN))
{
        $db = Database::instance();

        $db->begin();

        try
        {
            // `users`

            $userData['password'] = Arr::get($userData, 'password', Generate::generatePassword(Generate::PWD_TYPE_6_NUMBERS));

            $this->values($userData);

            $this->check();
            $this->save();

            $userId = $this->id;

            // `user_profile`

            $userProfileId = ORM::factory('User_Profile')->createUserProfile($userId, $userProfileData);

            // `roles_users`

            $this->add('roles', $userRoles);

            // ...

            $db->commit();

            return $userId;
        }
        catch(Database_Exception $exception)
        {
            $exception->getMessage();
            $db->rollback();

            return FALSE;
        }

        return FALSE;
    }

So, it looks very strong and massive. And if your models are not simple (for creating 1 essence you need to create related nodes in other tables), you already must use the transactions.

I am not really sure, that it is not OK and transactions need into ORM, but we can discuss about that :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions