Function in entity causes too many sql queries

the code below, in an entity, causes too many sql queries. A complete Contrat query (which is not needed) get generated for each Dailyreport …
I do not know exactly if this called a lazy loader.
The issue is that it is used with no problems in other parts of the software. But for the report I have to make with a lot of daily reports, it causes nginx / php timeout. If I comment out the code, and get my contrats differently, my report works… but the software is broken in other functionnalities.

Any solution is welcome.

 protected function _getContrat() {
        $contrats = TableRegistry::get('Contrats');
        return $contrats
            ->get($this->contrat_id, [
                "contain" => [
                    'Localisations',
                    'Localisations.Clients',
                    'Entreprises',
                ]
            ]);
    }

you are not saving this query results anywhere in entity, so when you do

foreach($results as $result) {
    $result->contrat;
}

the query is executed everytime! just save it somewhere in entity i.e.

protected function _getContrat() {
	if (!$this->_contrats) {
		$contrats = TableRegistry::get('Contrats');
		$this->_contrats = $contrats
			->get($this->contrat_id, [
				"contain" => [
					'Localisations',
					'Localisations.Clients',
					'Entreprises',
				]
			]);
	}
	return $this->_contrats;
}

EDIT:
this kind of getter is useful only on single entity, if you have many entities its way better to use ->contain on main query

Thank you very, very, very much Graziel !! My supervisor tweaked your proposal to fit our needs. (code below) I will now be studying how these entities, _properties, and all of that work.

 protected function _getContrat() {
        if (!isset($this->_properties["contrat"])) {
            $contrats = TableRegistry::get('Contrats');
            $this->_properties["contrat"] = $contrats
                ->get($this->contrat_id, [
                    "contain" => [
                        'Localisations',
                        'Localisations.Clients',
                        'Entreprises',
                    ]
                ]);
        }
        return $this->_properties["contrat"];
    }