Skip to content

Commit c24994c

Browse files
author
Phalcon
committed
Merge pull request #1519 from dreamsxin/selectWriteConnection
Add support \Phalcon\Mvc\Model::selectWriteConnection
2 parents beb8b47 + 48aeb82 commit c24994c

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

ext/mvc/model/query.c

+33-6
Original file line numberDiff line numberDiff line change
@@ -4038,8 +4038,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){
40384038
/**
40394039
* Get the model connection
40404040
*/
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+
}
40434052

40444053
PHALCON_OBS_VAR(meta_data);
40454054
phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
@@ -4380,8 +4389,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){
43804389
phalcon_call_method_p1(model, manager, "load", model_name);
43814390
}
43824391

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+
}
43854403

43864404
PHALCON_INIT_VAR(dialect);
43874405
phalcon_call_method(dialect, connection, "getdialect");
@@ -4630,8 +4648,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){
46304648
RETURN_MM();
46314649
}
46324650

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+
}
46354662

46364663
/**
46374664
* Create a transaction in the write connection

0 commit comments

Comments
 (0)