<commit_before><?php

App::uses('AppModel', 'Model');

/**
 * TemplateElement Model
 *
*/
class TemplateElement extends AppModel {
	public $actsAs = array('Containable');
	public $hasMany = array(
		'TemplateElementAttribute' => array(
			'dependent' => true
		), 
		'TemplateElementText' => array(
			'dependent' => true
		), 		
		'TemplateElementFile' => array(
			'dependent' => true
		)
	);
	public $belongsTo = array('Template');
	
	public function lastPosition($template_id) {
		$result = $this->find('first', array(
			'fields' => array('MAX(position) AS pos', 'id', 'template_id'),
			'conditions' => array('template_id' => $template_id)
		));
		return $result[0]['pos'];
	}
}<commit_msg>fix: Fix to an error with MISP and MySQL 5.7+ caused by no order clause on a distinct select query, fixes #1188<commit_after><?php

App::uses('AppModel', 'Model');

/**
 * TemplateElement Model
 *
*/
class TemplateElement extends AppModel {
	public $actsAs = array('Containable');
	public $hasMany = array(
		'TemplateElementAttribute' => array(
			'dependent' => true
		), 
		'TemplateElementText' => array(
			'dependent' => true
		), 		
		'TemplateElementFile' => array(
			'dependent' => true
		)
	);
	public $belongsTo = array('Template');
	
	public function lastPosition($template_id) {
		$result = $this->find('first', array(
			'fields' => array('MAX(position) AS pos', 'id', 'template_id'),
			'conditions' => array('template_id' => $template_id),
			'order' => array('id')
		));
		return $result[0]['pos'];
	}
}
{'fraction_non_alphanumeric': 0.17930125247198417, 'fraction_numerical': 0.005273566249176005, 'mean_word_length': 4.48014440433213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '2335262', 'n_tokens_mistral': 544, 'n_tokens_neox': 490, 'n_words': 117}