-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phalcon ORM writeAttribute when value is an associative array #14021
Comments
I also noticed this yesterday when I was working on other Model related issues. |
I did some testing and this bug is confirmed, but only occurs when For example: class Users extends Model
{
public $id;
public $name;
} $user = new Users();
$user->writeAttribute('whatEverUndefinedProperty', ['id' => 123, 'name' => 'My Name']);
// or
$user->whatEverUndefinedProperty = ['id' => 123, 'name' => 'My Name'];
print_r($user->toArray()); results in: Array
(
[id] => 123
[name] => My Name
) |
Actually it is important feature and we can not just remove this behavior from 3.x branch because:
|
@sergeyklay, I couldn't find this anywhere in the docs |
As a far as I know for 4.x this should be changed in #13677 |
That PR did not solve this, the code on line 359 causes this issue. |
Well, @wajdijurry pointed current issue for
The main idea is (as I said before) that we cannot change this for the 3.x branch. I personally was a part in battles long in a months, as soon as we changed something in area of Model:: |
All right, I am writing tests now to cover these functions and the open issues related to them. |
@sergeyklay what issue we are talking about ? I think it's a bug in Phalcon! |
As a far as I remember this feature was introduced in 2.x branch. So no, it is not a bug, it is well know behavior. This is why I said we can't this change for 3.x |
I think this function was meant to be working this way: class RobotsParts extends Model
{
public function initialize()
{
$this->belongsTo('robots_id', 'Robots', 'id', ['alias' => 'robot']);
}
} If we set the related record as an array: $robotPart = new Models\RobotsParts();
$robotPart->robot = ['name' => 'TestRobotName'];
$robot = $robotPart->robot;
var_dump(get_class($robot));
print_r($robot->toArray()); The result should be: string(6) "Robots"
Array
(
[name] => "TestRobotName"
) |
Resolved in #14035 |
Good job guys! Appreciate your effort |
When using
$model->writeAttribute('field', ['a'=>'apply', 'b'=>'banana'])
to write an associative array to an attribute in the model, the result is strange.Expected and Actual Behavior
Expected result:
Actual result:
This behavior happening when trying to write a new attribute to a model, and the value must be an associative array.
Details
3.4.2
)7.2.15
)The text was updated successfully, but these errors were encountered: