CakePHP 3.1 patchEntity всегда помечает принадлежащие ассоциации как грязные, когда чистые

Итак, я заметил, что если я исправляю сущность (метод редактирования) и внесу ли я какие-либо изменения в запись, если она имеет связи с ToMany, она помечает их как грязные. Я ожидаю, что если я не внесу никаких изменений в множественный выбор BTM в представлении, данные не будут загрязнены, только если после добавления или удаления параметров множественного выбора они будут помечены как грязные.

Данные сохраняются правильно, они просто грязные, но мне нужно действовать, чтобы знать, грязные они или чистые, поскольку у меня есть _join данные в моей таблице карт. Таблица карт называется users_locations и имеет id, user_id, location_id и static, где static это tinyint / bool.

Я пытаюсь сделать флаг статическим только для вновь созданных записей таблицы карт.

Я заметил, что patchEntity удаляет _joinData как часть процесса маршалинга.

Итак, глядя на выходные данные отладки, вы можете увидеть, что _joinData удаляется после исправления местоположений и user_occupations.

Мне кажется нежелательным не знать, являются ли связанные данные чистыми или грязными. Может быть, это было задумано, и я что-то упустил. Мысли?

В форме редактирования у меня есть:

<?php echo $this->Form->input('locations._ids', ['options' => $locations]) ?>

В контроллере у меня есть:

<?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']);
}
?>

В модели у меня это в функции инициализации для пользователя:

$this->belongsToMany('Locations', [
'through' => 'Users.UsersLocations',
'foreignKey' => 'user_id',
'targetForeignKey' => 'location_id',
'className' => 'Locations.Locations'
]);

Это результат отладки данных запроса:

[
'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'
]
]
]

Это пользовательская сущность перед исправлением с данными запроса:

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'

}

Вот как выглядят выходные данные отладки после исправления с данными запроса:

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'

}

5

Решение

Пожалуйста, откройте вопрос в https://github.com/cakephp/cakephp/issues.

Спасибо!

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector