Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add transaction feature to ORM #110

Open
ghost opened this issue Feb 3, 2015 · 0 comments
Open

Add transaction feature to ORM #110

ghost opened this issue Feb 3, 2015 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 3, 2015

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 :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants