Closed JT501 closed 5 years ago
Version Information PHP Version: 7.3 Package Version (l5-api): 1.0.3
Describe the bug The Primary got unset in response.
To Reproduce Steps to reproduce the behavior: Set $primaryKey = 'id' in Model. Return response using BaseTransformer.
Expected behavior Data with primary key.
Additional context nope
I managed to find out the bug in RestfulTransformer.php.
RestfulTransformer.php
/** * Primary Key transformation - all PKs to be called "id" */ $transformed = array_merge( ['id' => $model->getKey()], $transformed ); unset($transformed[$model->getKeyName()]);
I added if condition to check if the primary key equal to 'id' or not, before the unset action.
/** * Primary Key transformation - all PKs to be called "id" */ $transformed = array_merge( ['id' => $model->getKey()], $transformed ); if ($model->getKeyName() != 'id') { unset($transformed[$model->getKeyName()]); }
I have submitted a pull request to l5-api
Thanks for reporting! I will check out the PR
Merged, thanks !
Version Information PHP Version: 7.3 Package Version (l5-api): 1.0.3
Describe the bug The Primary got unset in response.
To Reproduce Steps to reproduce the behavior: Set $primaryKey = 'id' in Model. Return response using BaseTransformer.
Expected behavior Data with primary key.
Additional context nope
I managed to find out the bug in
RestfulTransformer.php
.I added if condition to check if the primary key equal to 'id' or not, before the unset action.