How is YII2 's affairs specific execution, why I do not rollback after SQL error?

Source: Internet
Author: User
Tags sql error
According to, Http://www.digpage.com/active_record.html,

I set up a transaction that relates to the add and delete operations of the table. afterSavebeforeDelete

Under normal circumstances, there is no problem with the association operation. A, B 2 table data is expected.

I called the B table name modification in the database. At this point the SQL statement is definitely not executable. Yii Direct error (This is also true, because the related table cannot be found.)

After the error, and then view the database, a table record has been deleted, but the B table records the existence of any.

My question is that the records of Table B are right. Because SQL did not execute successfully. But why is the record of a table also deleted? The transaction has been enabled. Why not roll it back?

I have a very good level of food, is not my understanding of the business error.

Does it mean that a transaction is only valid if the basic operation of the database is normal?

For example, just when the logic error, only need to 人为(当然这里是框架帮我们搞了) trigger rollback, has reached the operational requirements of the transaction?

Reply content:

According to, Http://www.digpage.com/active_record.html,

I set up a transaction that relates to the add and delete operations of the table. afterSavebeforeDelete

Under normal circumstances, there is no problem with the association operation. A, B 2 table data is expected.

I called the B table name modification in the database. At this point the SQL statement is definitely not executable. Yii Direct error (This is also true, because the related table cannot be found.)

After the error, and then view the database, a table record has been deleted, but the B table records the existence of any.

My question is that the records of Table B are right. Because SQL did not execute successfully. But why is the record of a table also deleted? The transaction has been enabled. Why not roll it back?

I have a very good level of food, is not my understanding of the business error.

Does it mean that a transaction is only valid if the basic operation of the database is normal?

For example, just when the logic error, only need to 人为(当然这里是框架帮我们搞了) trigger rollback, has reached the operational requirements of the transaction?

Not set to open transaction?

public function transactions(){    return [        self::SCENARIO_DEFAULT => self::OP_INSERT | self::OP_DELETE    ];}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.