@@ -4038,8 +4038,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){
4038
4038
/**
4039
4039
* Get the model connection
4040
4040
*/
4041
- PHALCON_INIT_VAR (connection );
4042
- phalcon_call_method (connection , model , "getwriteconnection" );
4041
+ if (phalcon_method_exists_ex (model , SS ("selectwriteconnection" ) TSRMLS_CC ) == SUCCESS ) {
4042
+ PHALCON_INIT_VAR (connection );
4043
+ phalcon_call_method_p3 (connection , model , "selectwriteconnection" , intermediate , bind_params , bind_types );
4044
+ if (Z_TYPE_P (connection ) != IS_OBJECT ) {
4045
+ PHALCON_THROW_EXCEPTION_STR (phalcon_mvc_model_exception_ce , "'selectWriteConnection' didn't returned a valid connection" );
4046
+ return ;
4047
+ }
4048
+ } else {
4049
+ PHALCON_INIT_VAR (connection );
4050
+ phalcon_call_method (connection , model , "getwriteconnection" );
4051
+ }
4043
4052
4044
4053
PHALCON_OBS_VAR (meta_data );
4045
4054
phalcon_read_property_this (& meta_data , this_ptr , SL ("_metaData" ), PH_NOISY_CC );
@@ -4380,8 +4389,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){
4380
4389
phalcon_call_method_p1 (model , manager , "load" , model_name );
4381
4390
}
4382
4391
4383
- PHALCON_INIT_VAR (connection );
4384
- phalcon_call_method (connection , model , "getwriteconnection" );
4392
+ if (phalcon_method_exists_ex (model , SS ("selectwriteconnection" ) TSRMLS_CC ) == SUCCESS ) {
4393
+ PHALCON_INIT_VAR (connection );
4394
+ phalcon_call_method_p3 (connection , model , "selectwriteconnection" , intermediate , bind_params , bind_types );
4395
+ if (Z_TYPE_P (connection ) != IS_OBJECT ) {
4396
+ PHALCON_THROW_EXCEPTION_STR (phalcon_mvc_model_exception_ce , "'selectWriteConnection' didn't returned a valid connection" );
4397
+ return ;
4398
+ }
4399
+ } else {
4400
+ PHALCON_INIT_VAR (connection );
4401
+ phalcon_call_method (connection , model , "getwriteconnection" );
4402
+ }
4385
4403
4386
4404
PHALCON_INIT_VAR (dialect );
4387
4405
phalcon_call_method (dialect , connection , "getdialect" );
@@ -4630,8 +4648,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){
4630
4648
RETURN_MM ();
4631
4649
}
4632
4650
4633
- PHALCON_INIT_VAR (connection );
4634
- phalcon_call_method (connection , model , "getwriteconnection" );
4651
+ if (phalcon_method_exists_ex (model , SS ("selectwriteconnection" ) TSRMLS_CC ) == SUCCESS ) {
4652
+ PHALCON_INIT_VAR (connection );
4653
+ phalcon_call_method_p3 (connection , model , "selectwriteconnection" , intermediate , bind_params , bind_types );
4654
+ if (Z_TYPE_P (connection ) != IS_OBJECT ) {
4655
+ PHALCON_THROW_EXCEPTION_STR (phalcon_mvc_model_exception_ce , "'selectWriteConnection' didn't returned a valid connection" );
4656
+ return ;
4657
+ }
4658
+ } else {
4659
+ PHALCON_INIT_VAR (connection );
4660
+ phalcon_call_method (connection , model , "getwriteconnection" );
4661
+ }
4635
4662
4636
4663
/**
4637
4664
* Create a transaction in the write connection
0 commit comments