Avoid 'Query data' in results

Hi, I realised that after doing a query with CakePHP (3.x) you get the specified data, but also some kind of query results. The following controller code…

$userQuery = $this->Users->find('all')
                ->where(['username' => 'tester']);
        
        $userR = $userQuery->first();

debug($userR);

…Outputs the following:

object(App\Model\Entity\User) {

	'id' => (int) 2,
	'username' => 'tester',
	'password' => '$2y$10$.yhyhz9uoLhUk8eQbEYb0Okk33z42kBztsk7iuYj5nvbwctUbOE7S',
	'role' => 'user',
	'name' => 'Test Account',
	'approved' => false,
	'created' => object(Cake\I18n\FrozenDate) {

		'time' => '2016-07-03T00:00:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'modified' => object(Cake\I18n\FrozenDate) {

		'time' => '2016-07-03T00:00:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'[new]' => false,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'Users'

}

The last eight entries have keys with brackets and are not in the model.
Where did these entries come from? Is there a way of avoiding or purging them?

Thanks in advance!

They are the entity class’ properties. Why do you want to get rid of them? They create no harm.

Ah, so that’s where they come from.

As a part of my cookie ‘stay logged in’ code I need to log a user in without having them type their password, so I use $myUser = $this->User->get(...) followed by Auth->setUser($myUser).
This however returns errors because of the eight extra array entries that are not part of the User model, so that’s why.

It’s a little late, though I still want to share my solution.

Calling toArray() on the result set creates a nice clean list, without the extra data, which passes into Auth->setUser() without any problems!