Skip to content

Commit

Permalink
Merge pull request #2523 from dreamsxin/model__set
Browse files Browse the repository at this point in the history
Fix #2351 \Phalcon\Mvc\Model::__set
  • Loading branch information
Phalcon committed Jun 14, 2014
2 parents a840979 + 31c2307 commit 15918f3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ext/mvc/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -6388,7 +6388,7 @@ PHP_METHOD(Phalcon_Mvc_Model, __set){
zval *property, *value, *lower_property = NULL;
zval *meta_data = NULL, *column_map = NULL, *attributes = NULL;
zval *related, *key = NULL, *lower_key = NULL, *item = NULL, *model_name, *manager = NULL;
zval *relation = NULL, *new_instance, *referenced_model_name = NULL, *referenced_model = NULL;
zval *relation = NULL, *referenced_model_name = NULL, *referenced_model = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
Expand Down Expand Up @@ -6458,19 +6458,16 @@ PHP_METHOD(Phalcon_Mvc_Model, __set){
i++;
phalcon_array_append(&related, item, 0);
}
} else {
} else if (Z_TYPE_P(key) == IS_STRING) {
PHALCON_INIT_NVAR(lower_key);
phalcon_fast_strtolower(lower_key, key);

phalcon_update_property_zval_zval(this_ptr, lower_key, item TSRMLS_CC);

PHALCON_CALL_METHOD(&relation, manager, "getrelationbyalias", model_name, lower_property);
if (Z_TYPE_P(relation) == IS_OBJECT) {
PHALCON_INIT_VAR(new_instance);
ZVAL_FALSE(new_instance);

if (Z_TYPE_P(relation) == IS_OBJECT) {
PHALCON_CALL_METHOD(&referenced_model_name, relation, "getreferencedmodel");
PHALCON_CALL_METHOD(&referenced_model, manager, "load", referenced_model_name, new_instance);
PHALCON_CALL_METHOD(&referenced_model, manager, "load", referenced_model_name, PHALCON_GLOBAL(z_false));
PHALCON_CALL_METHOD(NULL, referenced_model, "writeattribute", lower_key, item);
}
}
Expand Down

0 comments on commit 15918f3

Please sign in to comment.