migrating cakephp 2.5 code to use cakephp 3.0 objects - php

I migrating a 2.5 app to cakePHP 3.0 and I am updating my code to use the ORM objects after find() rather than the arrays.
In my 2.5 view I do an array find and count the results. But I cannot seem to access the object level I need to do the count in the new code.
2.5 Code:
<?php foreach ($recentEmployees as $recentEmployee): ?>
<tr>
<td>
<?php echo ($recentEmployee['Employee']['name']); ?>
</td>
<td><?php echo h($this->Time->format('d/m/Y', $recentEmployee['Employee']['created'])); ?></td>
<td>
<?php
$completedCourses = count(
array_filter(
$recentEmployee['Course'],
function($item){return $item['CoursesEmployee']['completed'];}
)
);
$totalCourse = count($recentEmployee['Course']);
?>
<span class="label <?php echo($label); ?>">
<?php
echo ($completedCourses);
?>
/<?php echo ($totalCourse); ?>
</td>
</tr>
<?php endforeach; ?>
Now my 3.0 code and the object I am trying access and count:
<?php foreach ($recentEmployees as $recentEmployee): ?>
<tr>
<td><?= h($recentEmployee->name) ?></td>
<td><?= h($this->Time->format($recentEmployee->created, 'd/M/Y')) ?></td>
<td><?= debug($recentEmployee->courses) ?></td>
</tr>
<?php endforeach; ?>
Object:
[
(int) 0 => object(App\Model\Entity\Course) {
'id' => (int) 1,
'name' => 'Manual Handling Training',
'course_lenght' => object(Cake\I18n\Time) {
'time' => '2015-05-28T02:12:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(App\Model\Entity\CoursesEmployee) {
'course_id' => (int) 1,
'id' => (int) 1,
'employee_id' => (int) 1,
'course_module_id' => (int) 5,
'progress' => (int) 10,
'modified' => object(Cake\I18n\Time) {
'time' => '2014-12-16T22:40:42+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'created' => object(Cake\I18n\Time) {
'time' => '2014-11-18T00:00:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'completed' => false,
'[new]' => false,
'[accessible]' => [
'employee_id' => true,
'course_id' => true,
'course_module_id' => true,
'progress' => true,
'completed' => true,
'employee' => true,
'course' => true,
'course_module' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'CoursesEmployees'
},
'[new]' => false,
'[accessible]' => [
'name' => true,
'course_lenght' => true,
'course_files' => true,
'course_modules' => true,
'employees' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Courses'
},
(int) 1 => object(App\Model\Entity\Course) {
'id' => (int) 3,
'name' => 'Treacys Hotel Induction Training',
'course_lenght' => object(Cake\I18n\Time) {
'time' => '2015-05-28T01:25:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(App\Model\Entity\CoursesEmployee) {
'course_id' => (int) 3,
'id' => (int) 2,
'employee_id' => (int) 1,
'course_module_id' => (int) 8,
'progress' => (int) 100,
'modified' => object(Cake\I18n\Time) {
'time' => '2014-12-08T00:07:18+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'created' => object(Cake\I18n\Time) {
'time' => '2014-11-20T00:00:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'completed' => true,
'[new]' => false,
'[accessible]' => [
'employee_id' => true,
'course_id' => true,
'course_module_id' => true,
'progress' => true,
'completed' => true,
'employee' => true,
'course' => true,
'course_module' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'CoursesEmployees'
},
'[new]' => false,
'[accessible]' => [
'name' => true,
'course_lenght' => true,
'course_files' => true,
'course_modules' => true,
'employees' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Courses'
},
]
I have tried this but it is a bad mess of objects and arrays
$completedCourses = count(
array_filter(
$recentEmployee->courses,
function($item){return $item['CoursesEmployee']['completed'];}
)
);
****UPDATE
I have accessed the data by pointing in _jointable. This is surely not the best practice?
<?= $completedCourses = count(
array_filter(
$recentEmployee->courses,
function($item){return $item['_joinData']['completed'];}
)
);?>

Seems okay to me, but you could do the count via find in your action code.
to avoid the join you could use the object access method...
<?= $completedCourses = count(
array_filter(
$recentEmployee->courses,
function($item){return $item->completed;}
)
);?>

Related

how do I get all associated data for a given ID in CakePhp 3 using get()?

Here is my situation....
I can view item details based on item ID passed from GUI
public function view($id = null){
$id = $this->request->getData('assetsource_id');
$assetSource = $this->AssetSources->get($id, [
'contain' => ['Assets']
]);
debug($assetSource);
die();
$this->set('assetSource', $assetSource);
$this->set('_serialize', ['assetSource']);
When I debug, I get the following except...
/src/Controller/AssetSourcesController.php (line 64)
object(App\Model\Entity\AssetSource) {
'id' => (int) 18,
'name' => 'Donated',
'created_by' => '',
'assets' => [
(int) 0 => object(App\Model\Entity\Asset) {
'id' => (int) 1,
'school_unit_id' => (int) 33,
'asset_source_id' => (int) 18,
'asset_description' => 'TOYOTA HILUX',
'date_of_entry' => object(Cake\I18n\FrozenDate) {
'time' => '2021-05-31T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'date_of_purchase' => object(Cake\I18n\FrozenDate) {
'time' => '2021-05-31T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'grn_number' => 'KBHBBH92',
'name_of_supplier' => 'TOYOTA ZAMBIA',
'serial_number' => 'YTDIYTFYUFOGOOHH',
'location' => 'BURSAR',
'asset_category_id' => (int) 24,
'asset_group_class_id' => (int) 65,
'full_asset_number' => 'GGFUYG88',
'condition_id' => (int) 12,
'asset_status_id' => (int) 14,
'value' => '400,000',
'custodian_name' => 'JOE BANDA',
'custodian_phone' => '0966010101',
'custodian_email' => 'bursar#unza.zm',
'created' => object(Cake\I18n\FrozenTime) {
'time' => '2021-05-31T07:26:31+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2021-05-31T07:26:31+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'created_by' => 'admin',
'[new]' => false,
'[accessible]' => [
'*' => true,
'id' => false
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Assets'
}
],
'[new]' => false,
'[accessible]' => [
'*' => true,
'id' => false
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'AssetSources'
}
Except when I pass the result to the view.ctp, school_unit_id, asset_source_id, asset_category_id, asset_group_class_id, condition_id, asset_status_id are showing the corresponding IDs as saved in Assets table.
<?php foreach ($assetSource->assets as $assets) : ?>
<tr>
<td><?php echo $i++ ?></td>
<td><?= h($assets->school_unit_id) ?></td>
<td><?= h($assets->asset_description) ?></td>
<td><?= h($assets->date_of_purchase) ?></td>
<td><?= h($assets->name_of_supplier) ?></td>
<td><?= h($assets->location) ?></td>
<td><?= h($assets->condition_id) ?></td>
<td><?= h($assets->value) ?></td>
<td><?= h($assets->custodian_name) ?></td>
</tr>
<?php endforeach; ?>
How do I show the respective display fields instead of IDs? Notice asset_sources table is only associated to assets table. Then assets table is associated to school_units, asset_sources, asset_categories, asset_group_classes, conditions, asset_status tables. In my view. I want to see school_unit_name not school_unit_id. NOTE: I used bake commands to create the application.
Thanks
Read up on containment. It will let you include whatever you want. 'contain' => ['Assets' => ['SchoolUnits']] should work here, and then you can use $assets->school_unit->name or something like that in your view.

select and contain do not work in cakephp query

When I query without select() I get contain() [owner] array, but using select() with params it doesn't contain [owner] array. Is there any problem using select and contain at same time ?
$payments = $this->Payments->find()
->select($this->Payments)
->select(['tot_amount'=>'sum(Payments.amount)'])
->select(['tot_owner_amt'=>'sum(Payments.owner_amt)'])
->select(['tot_admin_amt'=>'sum(Payments.admin_amt)'])
->contain(['Owners'])
->group(['Payments.owner_id'])
->all();
debug($payments); die();
Debug array
\src\Controller\PaymentsController.php (line 72)
object(Cake\ORM\ResultSet) {
'items' => [
(int) 0 => object(App\Model\Entity\Payment) {
'id' => (int) 4,
'user_id' => (int) 4,
'owner_id' => (int) 5,
'wifi_id' => (int) 2,
'payment_unique_key' => 'pay-9999',
'payment_type' => 'paypal',
'amount' => (float) 10,
'owner_amt' => (float) 1,
'admin_amt' => (float) 9,
'ispaid' => false,
'paid_at' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:21:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'is_refund' => false,
'isactive' => true,
'isdel' => null,
'created' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:22:24+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:30:26+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'tot_amount' => '10.00',
'tot_owner_amt' => '1.00',
'tot_admin_amt' => '9.00',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Payments'
},
(int) 1 => object(App\Model\Entity\Payment) {
'id' => (int) 1,
'user_id' => (int) 1,
'owner_id' => (int) 6,
'wifi_id' => (int) 1,
'payment_unique_key' => 'adfasdf',
'payment_type' => 'paypal',
'amount' => (float) 500,
'owner_amt' => (float) 50,
'admin_amt' => (float) 449,
'ispaid' => false,
'paid_at' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:21:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'is_refund' => false,
'isactive' => true,
'isdel' => null,
'created' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:22:24+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:30:26+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'tot_amount' => '2000.00',
'tot_owner_amt' => '200.00',
'tot_admin_amt' => '1798.00',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Payments'
}
]
}
Did i miss anything in above code? Thanks in advance
If you don't select the owner data it doesn't fetch the owner? Pretty simple as that. You select only the payments, add the owner like you do with the payments.
Need to select the owners array in select like select($this->Payments->Owners) , Thanks #burzum
Solutions
$payments = $this->Payments->find()
->select($this->Payments)
->select(['tot_amount'=>'sum(Payments.amount)'])
->select(['tot_owner_amt'=>'sum(Payments.owner_amt)'])
->select(['tot_admin_amt'=>'sum(Payments.admin_amt)'])
->select($this->Payments->Owners)
->contain(['Owners'])
->group(['Payments.owner_id'])
->all();

In CakePHP 3, how can I create a new Entity with BelongsToMany records including join data?

In the parlance of the classic BelongsToMany example, I'm trying to create a new Student with associated Courses records, and final_grade data for each of the Student's Courses. (The Courses records themselves already exist.) When I attempt to create the Student, I'm sending courses[0][_joinData][course_id] and courses[0][_joinData][final_grade], but when it tries to save the new CoursesStudents record, the validation complains that it doesn't have a student_id field. I'm not able to pass it in, because it doesn't exist yet!
I can associate the new Student records with existing Courses by sending data as courses[_ids], and that correctly picks up the newly provisioned Course's id for the course_id for the join table's new record. But I haven't been able to figure out a way to include non-default join data.
(My real models are AccessGroups and Markets, but the relationships are the same. I want to be able to associate a new AccessGroup with an existing Market at a specific access_level at the time of creation, without having to generate the AccessGroupsMarkets record after the fact.)
Edit
Code:
I'm adding my code and the responses I'm getting back from CakePHP, as suggested by #burzum:
// in a controller
$accessGroupsTable = TableRegistry::get('AccessGroups');
$data = [
'name' => 'Test for Access Group with Market Join Data',
'access_group_type_id' => '1',
'project_id' => '49',
'markets' => [
0 => [
'id' => '46',
'_joinData' => [
'market_id' => '46',
'access_level' => '2',
]
],
1 => [
'id' => '47',
'_joinData' => [
'market_id' => '47',
'access_level' => '2',
]
]
],
];
$newAccessGroup = $accessGroupsTable->newEntity($data);
debug(["newAccessGroup", $newAccessGroup], false); // debug!
$saved = $accessGroupsTable->save($newAccessGroup);
debug(["saved", $saved], false); // debug!
Response:
/src/Controller/AccessGroupsController.php (line 161)
########## DEBUG ##########
[
(int) 0 => 'newAccessGroup',
(int) 1 => object(App\Model\Entity\AccessGroup) {
'name' => 'Test for Access Group with Market Join Data',
'access_group_type_id' => (int) 1,
'project_id' => (int) 49,
'markets' => [
(int) 0 => object(App\Model\Entity\Market) {
'id' => (int) 46,
'project_id' => (int) 49,
'name' => 'United States - Flammmo',
'created' => object(Cake\I18n\Time) {
'time' => '2016-05-13T18:42:11+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2016-05-13T18:42:11+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'deleted' => null,
'_joinData' => object(App\Model\Entity\AccessGroupsMarket) {
'market_id' => (int) 46,
'access_level' => (int) 2,
'[new]' => true,
'[accessible]' => [
'market_id' => true,
'access_group_id' => true,
'access_level' => true
],
'[dirty]' => [
'market_id' => true,
'access_level' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [
'access_group_id' => [
'_required' => 'This field is required'
]
],
'[invalid]' => [],
'[repository]' => 'AccessGroupsMarkets'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => [
'market_id' => '46',
'access_level' => '2'
]
],
'[virtual]' => [
(int) 0 => 'flag_url'
],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Markets'
},
(int) 1 => object(App\Model\Entity\Market) {
'id' => (int) 47,
'project_id' => (int) 49,
'name' => 'Indonesia - Flammmo',
'created' => object(Cake\I18n\Time) {
'time' => '2016-06-24T16:24:57+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2016-06-24T16:24:57+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'deleted' => null,
'_joinData' => object(App\Model\Entity\AccessGroupsMarket) {
'market_id' => (int) 47,
'access_level' => (int) 2,
'[new]' => true,
'[accessible]' => [
'market_id' => true,
'access_group_id' => true,
'access_level' => true
],
'[dirty]' => [
'market_id' => true,
'access_level' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [
'access_group_id' => [
'_required' => 'This field is required'
]
],
'[invalid]' => [],
'[repository]' => 'AccessGroupsMarkets'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => [
'market_id' => '47',
'access_level' => '2'
]
],
'[virtual]' => [
(int) 0 => 'flag_url'
],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Markets'
}
],
'[new]' => true,
'[accessible]' => [
'project_id' => true,
'access_group_type_id' => true,
'name' => true,
'slug' => true,
'features' => true,
'assets' => true,
'markets' => true,
'child_groups' => true,
'users' => true
],
'[dirty]' => [
'name' => true,
'access_group_type_id' => true,
'project_id' => true,
'markets' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'AccessGroups'
}
]
###########################
/src/Controller/AccessGroupsController.php (line 177)
########## DEBUG ##########
[
(int) 0 => 'saved',
(int) 1 => false
]
###########################
Note the validation errors on both of the markets' _joinData access_group_id
Working code that's not quite what I want
$accessGroupsTable = TableRegistry::get('AccessGroups');
$data2 = [
'name' => 'Test for Access Group with Market IDs',
'access_group_type_id' => '1',
'project_id' => '49',
'markets' => [
'_ids' => [ 46, 47 ],
],
];
$newAccessGroup = $accessGroupsTable->newEntity($data2);
$saved = $accessGroupsTable->save($newAccessGroup);
This code successfully creates the new AccessGroup, along with the associated new AccessGroupsMarkets records, but with the default values for access_level, not the value that I'd like to be able to specify.
#systematical asked about the table setup. They were generated from a migration and then cake/bake'd (see the Table associations)
The problem (pointed out by #npm on IRC #cakephp) was that I was doing validation on the foreign keys in my join table's model:
// in AccessGroupsMarketsTable::validationDefault
$validator
->requirePresence('access_group_id', 'create')
->notEmpty('access_group_id')
->add('access_group_id', 'valid', ['rule' => 'numeric']);
$validator
->requirePresence('market_id', 'create')
->notEmpty('market_id')
->add('market_id', 'valid', ['rule' => 'numeric']);
This was in addition to the $rules in buildRules:
$rules->add($rules->existsIn(['access_group_id'], 'AccessGroups'));
$rules->add($rules->existsIn(['market_id'], 'Markets'));
#npm suggested that I remove the validation for those foreign keys (keeping the $rules in place). And his suggestion works. I can now save the new AccessGroups entity with its related AccessGroupsMarkets records and their associated access_level information.

PHP delete object inside array

I have to delete some objects inside my action before sending data to the view
The data are something like this:
'items' => [
(int) 0 => object(App\Model\Entity\Propriete) {
'id_propriete' => (int) 1,
// and other fields
'user' => object(App\Model\Entity\User) {
'id' => '1459436853',
//and other fields
},
'favorites' => [
(int) 0 => object(App\Model\Entity\Favorite) {
'id' => (int) 24,
'propriete_id' => (int) 1,
'user_id' => '1459438630',
'created' => object(Cake\I18n\FrozenDate) {
'time' => '2016-04-15T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenDate) {
'time' => '2016-04-15T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
},
(int) 1 => object(App\Model\Entity\Favorite) {
'id' => (int) 27,
'propriete_id' => (int) 1,
'user_id' => '1459436853',
,
'modified' => object(Cake\I18n\FrozenDate) {
'time' => '2016-04-18T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Favorites'
},
(int) 2 => object(App\Model\Entity\Favorite) {
'id' => (int) 28,
'propriete_id' => (int) 1,
'user_id' => 'ae0dce23-584b-4907-b32e-1655d5e69e55',
}
],
}
]
favorites is an array i want to remove some specific object inside this array according to a condition..
So that what i tried to do :
foreach($proprietes as $ad){
foreach($ad->favorites as $favori)
if($favori->user_id !==$user['id']){
unset($favori);
}
}
Butit doesn't work can some one help ?
foreach($proprietes as $ad){
foreach($ad->favorites as $key=>$favori)
if($favori->user_id !==$user['id']){
unset($ad->favorites[$key]);
}
}
You have to reference the object directly.

CakePHP 3.1 patchEntity always marking belongsToMany associations as dirty when clean

So I noticed that If I patch an entity (edit method) and whether or not I make any data changes to the record if it has belongsToMany associations it marks them as dirty. I would expect that if I make no changes to the BTM multiple select in the view the data would not be dirty, only if the adding or removing options in the multiple select would it be marked as dirty after patching.
The data does save correctly, it is just dirty, but I need to act on know if it is dirty or clean as I have _join data in my map table. The map table is named users_locations and has id, user_id, location_id and static where static is a tinyint/bool.
What I am trying to do is flag static only for newly created map table entries.
What I notice is that patchEntity is stripping the _joinData as part of the marshaling process.
So looking at the debug output below you can see that the _joinData is stripped after patching for locations and user_occupations both.
This seems undesirable to me to not know if the associated data is clean or dirty. Maybe it was intended to work this way and I am missing something. Thoughts?
In the edit form I have:
<?php echo $this->Form->input('locations._ids', ['options' => $locations]) ?>
In the controller I have:
<?php
public function edit($id = null)
{
$user = $this->Users->get($id, [
'contain' => ['Locations', 'UserOccupations']
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
$securityGroups = $this->Users->SecurityGroups->find('list');
$locations = $this->Users->Locations->find('list', [
'order' => ['Locations.name' => 'ASC'],
'keyField' => 'id',
'valueField' => 'name',
'limit' => 200
]);
$userOccupations = $this->Users->UserOccupations->find('list');
$this->set(compact('user', 'securityGroups', 'locations', 'userOccupations'));
$this->set('_serialize', ['user']);
}
?>
In the model I have this in the initialize function for User:
$this->belongsToMany('Locations', [
'through' => 'Users.UsersLocations',
'foreignKey' => 'user_id',
'targetForeignKey' => 'location_id',
'className' => 'Locations.Locations'
]);
This is the request data debug output:
[
'Referer' => [
'url' => '/login'
],
'security_group_id' => '',
'username' => 'test',
'email' => 'test#test.com',
'prefix' => '',
'first_name' => 'test',
'middle_name' => '',
'last_name' => 'test',
'suffix' => '',
'credentials' => '',
'birthdate' => '',
'timezone' => 'America/New_York',
'theme' => '',
'locations' => [
'_ids' => [
(int) 0 => '7',
(int) 1 => '33'
]
],
'user_occupations' => [
'_ids' => [
(int) 0 => '1'
]
]
]
This is the user entity before patching with the request data:
object(Users\Model\Entity\User) {
'id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'identifier' => (int) 5,
'security_group_id' => null,
'sex_id' => null,
'username' => 'test',
'email' => 'test#test.com',
'prefix' => '',
'first_name' => 'test',
'middle_name' => '',
'last_name' => 'test',
'suffix' => '',
'credentials' => '',
'birthdate' => null,
'timezone' => 'America/New_York',
'theme' => '',
'ip' => '0.0.0.0',
'last_login' => null,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-16T16:17:57+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T22:22:49+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'user_occupations' => [
(int) 0 => object(Users\Model\Entity\UserOccupation) {
'id' => (int) 1,
'name' => 'Test',
'_joinData' => object(Cake\ORM\Entity) {
'user_occupation_id' => (int) 1,
'user_id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'UsersUserOccupations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UserOccupations'
}
],
'locations' => [
(int) 0 => object(Locations\Model\Entity\Location) {
'id' => (int) 7,
'ldap_name' => 'Test',
'name' => 'Test',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-11T19:35:34+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(Users\Model\Entity\UsersLocation) {
'location_id' => (int) 7,
'id' => (int) 304,
'user_id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'static' => false,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UsersLocations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
},
(int) 1 => object(Locations\Model\Entity\Location) {
'id' => (int) 33,
'ldap_name' => 'Test2',
'name' => 'Test2',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-15T21:03:46+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(Users\Model\Entity\UsersLocation) {
'location_id' => (int) 33,
'id' => (int) 305,
'user_id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'static' => false,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UsersLocations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
},
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [
(int) 0 => 'full_name',
(int) 1 => 'name_last_first'
],
'[errors]' => [],
'[repository]' => 'Users.Users'
}
This the what the debug output look like after patching with the request data:
object(Users\Model\Entity\User) {
'id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'identifier' => (int) 5,
'security_group_id' => null,
'sex_id' => null,
'username' => 'test',
'email' => 'test#test.com',
'prefix' => '',
'first_name' => 'test',
'middle_name' => '',
'last_name' => 'test',
'suffix' => '',
'credentials' => '',
'birthdate' => null,
'timezone' => 'America/New_York',
'theme' => '',
'ip' => '0.0.0.0',
'last_login' => null,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-16T16:17:57+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T22:22:49+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'user_occupations' => [
(int) 0 => object(Users\Model\Entity\UserOccupation) {
'id' => (int) 1,
'name' => 'Test ',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UserOccupations'
}
],
'locations' => [
(int) 0 => object(Locations\Model\Entity\Location) {
'id' => (int) 7,
'ldap_name' => 'Test',
'name' => 'Test',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-11T19:35:34+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
},
(int) 1 => object(Locations\Model\Entity\Location) {
'id' => (int) 33,
'ldap_name' => 'Test2',
'name' => 'Test2',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-15T21:03:46+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
}
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'locations' => true,
'user_occupations' => true
],
'[original]' => [
'locations' => [
(int) 0 => object(Locations\Model\Entity\Location) {
'id' => (int) 7,
'ldap_name' => 'Test',
'name' => 'Test',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-11T19:35:34+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(Users\Model\Entity\UsersLocation) {
'location_id' => (int) 7,
'id' => (int) 304,
'user_id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'static' => false,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UsersLocations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
},
(int) 1 => object(Locations\Model\Entity\Location) {
'id' => (int) 33,
'ldap_name' => 'Test2',
'name' => 'Test2',
'address' => null,
'address_2' => null,
'city' => 'Test',
'state' => 'MD',
'zip' => null,
'phone' => null,
'fax' => null,
'active' => true,
'created' => object(Cake\I18n\Time) {
'time' => '2015-09-15T21:03:46+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-16T21:47:29+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'_joinData' => object(Users\Model\Entity\UsersLocation) {
'location_id' => (int) 33,
'id' => (int) 305,
'user_id' => '8b7197a4-5633-4bda-a6c7-a6e16f7cad64',
'static' => false,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Users.UsersLocations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Locations.Locations'
},
]
],
'[virtual]' => [
(int) 0 => 'full_name',
(int) 1 => 'name_last_first'
],
'[errors]' => [],
'[repository]' => 'Users.Users'
}
Please open an issue in https://github.com/cakephp/cakephp/issues.
Thanks!

Categories