Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:14:05+00:00 2026-06-07T04:14:05+00:00

I am using innoDB based Database. How I can use the Transaction to save

  • 0

I am using innoDB based Database. How I can use the Transaction to save the data.

I have an array of users. But only saves the last record in the database. I can not use saveAll, because I have to save the data in multiple tables and all of them are interrelated.

I even can not define the model association-ship because there are huge number of entries in my database. So each time join will perform.

Please suggest how I can use the Transaction concept?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:14:07+00:00Added an answer on June 7, 2026 at 4:14 am

    All transactions are performed on the current DataSource object.

    Firstly you need to get it (in the model):

    $dataSrc = $this->getDataSource();
    

    This method returns the DataSource object that is currently bound to the Model.

    Then you can use the DataSource Object’s methods to begin, commit or rollback transactions:

    $dataSrc->begin();
    //Do something 
    
    if (/*Everything is nice?*/) {
        $dataSrc->commit();
    } else {
        //Bad things have happened
        $dataSrc->rollback();
    }
    

    You will have to implement your own logic of course. Since Cake 2.2 you can also do real nested transactions. A “nested transaction” according to Wikipedia is:

    A nested transaction occurs when a new transaction is started by an
    instruction that is already inside an existing transaction. The new
    transaction is said to be nested within the existing transaction,
    hence the term. Nested transactions are implemented differently in
    different databases. However, they have in common that the changes are
    not made visible to any unrelated transactions until the outermost
    transaction has committed. This means that a commit in an inner
    transaction does not necessary persist updates to the database.

    Of course all this is dependent on the Database you’re using. MySQL InnoDB transactional storage engine does support transactions.

    And another clarification in response to this comment:

    Yes, I am using $this->Model->saveAll($this->request->data,
    array(‘deep’ => true) in my controller. This is written under a
    foreach loop. And only the last foreach record is going to be saved
    into the database. – Arun Jain

    $this->Model->saveAll(); does NOT need to be run in a loop! It will manage things for you “automagically”. Take it out of the loop.
    Furthermore your question was concerning transactions, not saving data with saveAll(). Model::saveAll() is just a wrapper for saveMany() and saveAssociated() – it will choose which method to use depending on the type of Model association.

    Read the Cake Book it is all very well explained there…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Engine InnoDB on my MySQL server. I have a patch script
We're using MySQL with Innodb Engine storage. We have an evented environment that sends
I am using the following InnoDB tables in mysql to describe records that can
I have a webservice using Hibernate as DAL - using MySql with InnoDB. Since
Well, my friend told me I should start using InnoDB for my database, so
I have issues with using the MyISAM engine in my database. It is constantly
I have a table using innodb. I know the table has roughly 89 million
All of my tables are InnoDB but PHPMyAdmin shows that the database is MyIsam:
Is there an equivalent to a grouped primary key using an InnoDB MySQL database
I am trying to create a table in Drupal database using hook_schema function but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.