Yii2 Question: Is there any way to get the current insert
query before executing save? for instance $model->save()
. For the current situation, save is actually inserting a row in a table.
I know about executing function beforeSave($insert)
but this $insert only refers whether the event is valid or not, and does extra computation before saving in database.
Misc stuff: Find query can be printed as $FindResultVariable->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql;
If someone can think in this direction too for solution?
Thanks.
Asked
Active
Viewed 1,662 times
0

Danish Ahmed
- 171
- 1
- 9
-
What is the purpose of this? Is it for debugging? – Jørgen Feb 11 '16 at 13:31
-
If you have [yii2-debug](https://github.com/yiisoft/yii2-debug) enabled, you can click the DB section and see all queries executed on the selected page. You can switch pages with the "Last 10" dropdown at the top of the page. – Martijn Hols Feb 11 '16 at 13:31
-
i know about debugging stuff and it is enabled. The issue is with a weird case occurring on specific column. Same function is called for create and update - even the `$this->attributes` is same printing values on beforeSave(). And the Insert query on yii debug log has value of that column. But value is not saving for create. P.S: debug insert printed query has a value for that column. I can share screen shots if u want. – Danish Ahmed Feb 11 '16 at 13:53
-
Check length of that field. If you're passing long data to the field which has small allowed storage that this can happen. e.g. you have varchar(50) field and you're passing data more than 50. also try $model->getErrors(); after model save method. – Alpesh Panchal Feb 14 '16 at 06:23