<commit_before><?php
namespace App\Model\Table;

use Cake\Database\Query;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Players Model
 */
class PlayersTable extends Table {

/**
 * Initialize method
 *
 * @param array $config The configuration for the Table.
 * @return void
 */
	public function initialize(array $config) {
		$this->table('players');
		$this->displayField('FullName');
		$this->primaryKey('id');
		
		$this->addBehavior('Timestamp');
		$this->addBehavior('Sluggable', ['field' => 'FullName']);

		$this->belongsTo('PlayerSpecialisations', [
			'foreignKey' => 'player_specialisation_id',
		]);
		$this->belongsTo('Clubs', [
			'foreignKey' => 'club_id',
		]);
		$this->hasMany('Batsmen', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Bowlers', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Innings', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Squads', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'lost_wicket_player_id'
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'took_wicket_player_id'
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'bowler_player_id'
		]);
	}

/**
 * Default validation rules.
 *
 * @param Validator $validator
 * @return Validator
 */
	public function validationDefault(Validator $validator) {
		$validator
			->add('id', 'valid', ['rule' => 'uuid'])
			->allowEmpty('id', 'create')
			->validatePresence('first_name', 'create')
			->notEmpty('first_name')
			->validatePresence('last_name', 'create')
			->notEmpty('last_name')
			->validatePresence('slug', 'create')
			->notEmpty('slug')
			->allowEmpty('photo')
			->allowEmpty('photo_dir')
			->add('number', 'valid', ['rule' => 'numeric'])
			->allowEmpty('number')
			->allowEmpty('nationality')
			->allowEmpty('bats')
			->allowEmpty('bowls')
			->add('player_specialisation_id', 'valid', ['rule' => 'uuid'])
			->validatePresence('player_specialisation_id', 'create')
			->notEmpty('player_specialisation_id')
			->add('club_id', 'valid', ['rule' => 'uuid'])
			->validatePresence('club_id', 'create')
			->notEmpty('club_id');

		return $validator;
	}

/**
 * Find a list of players along with their associated club
 * 
 * @param Query $query
 * @return Query
 */
	public function findPlayerListByTeam(Query $query) {
		return $query
			->contain(['Clubs', 'PlayerSpecialisations'])
			->select([
				'Players.id', 'Players.first_name', 'Players.initials', 'Players.last_name', 
				'Clubs.id', 'Clubs.name',
				'PlayerSpecialisations.name'
			]);
	}
}
<commit_msg>Updated the custom finder to do some post processing to the data before it's output<commit_after><?php
namespace App\Model\Table;

use Cake\Database\Query;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Players Model
 */
class PlayersTable extends Table {

/**
 * Initialize method
 *
 * @param array $config The configuration for the Table.
 * @return void
 */
	public function initialize(array $config) {
		$this->table('players');
		$this->displayField('FullName');
		$this->primaryKey('id');
		
		$this->addBehavior('Timestamp');
		$this->addBehavior('Sluggable', ['field' => 'FullName']);

		$this->belongsTo('PlayerSpecialisations', [
			'foreignKey' => 'player_specialisation_id',
		]);
		$this->belongsTo('Clubs', [
			'foreignKey' => 'club_id',
		]);
		$this->hasMany('Batsmen', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Bowlers', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Innings', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Squads', [
			'foreignKey' => 'player_id',
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'lost_wicket_player_id'
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'took_wicket_player_id'
		]);
		$this->hasMany('Wickets', [
			'foreignKey' => 'bowler_player_id'
		]);
	}

/**
 * Default validation rules.
 *
 * @param Validator $validator
 * @return Validator
 */
	public function validationDefault(Validator $validator) {
		$validator
			->add('id', 'valid', ['rule' => 'uuid'])
			->allowEmpty('id', 'create')
			->validatePresence('first_name', 'create')
			->notEmpty('first_name')
			->validatePresence('last_name', 'create')
			->notEmpty('last_name')
			->validatePresence('slug', 'create')
			->notEmpty('slug')
			->allowEmpty('photo')
			->allowEmpty('photo_dir')
			->add('number', 'valid', ['rule' => 'numeric'])
			->allowEmpty('number')
			->allowEmpty('nationality')
			->allowEmpty('bats')
			->allowEmpty('bowls')
			->add('player_specialisation_id', 'valid', ['rule' => 'uuid'])
			->validatePresence('player_specialisation_id', 'create')
			->notEmpty('player_specialisation_id')
			->add('club_id', 'valid', ['rule' => 'uuid'])
			->validatePresence('club_id', 'create')
			->notEmpty('club_id');

		return $validator;
	}

/**
 * Find a list of players along with their associated club and specialisation
 * 
 * @param Query $query
 * @return Query
 */
	public function findPlayerListByTeam(Query $query) {
		$query->contain(['Clubs', 'PlayerSpecialisations'])
			->select([
				'Players.id', 'Players.first_name', 'Players.initials', 'Players.last_name',
				'Clubs.id', 'Clubs.name',
				'PlayerSpecialisations.name'
			]);

		// Function to concatenate the value field for the combine()
		$player = function($entity) {
			return $entity->first_name . ' ' . $entity->initials . ' ' . $entity->last_name . ' (' . $entity->player_specialisation->name . ')';
		};

		// Use a result formatter to run combine on the results to build a list
		$query->formatResults(function(ResultSetInterface $results, Query $query) use ($player) {
			return $results->combine('id', $player, 'club.name');
		});

		return $query;
	}
}

{'fraction_non_alphanumeric': 0.1974323386537127, 'fraction_numerical': 0.0, 'mean_word_length': 4.418233082706767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2992915', 'n_tokens_mistral': 2191, 'n_tokens_neox': 1920, 'n_words': 358}