# Query in cakephp 3

**URL:** https://discourse.cakephp.org/t/query-in-cakephp-3/7164
**Category:** Need Help
**Created:** [January 24, 2020, 1:39pm UTC](https://discourse.cakephp.org/t/query-in-cakephp-3/7164 "2020-01-24T13:39:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![schloter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@schloter](https://discourse.cakephp.org/u/schloter)
#### Post date: [January 24, 2020, 1:39pm UTC](https://discourse.cakephp.org/t/query-in-cakephp-3/7164/1 "2020-01-24T13:39:13Z")

</div>

I need help, I have a problem when I want to make a sql request in cakephp 3.2 here is the request in my model class:

namespace App\Model\Table;

use Cake\ORM\Table;  
use Cake\ORM\TableRegistry;

class MarchesTable extends Table  
{  
public function initialize(array $config)  
{  
$this-\>primaryKey(‘num\_contrat’);  
}

```
public function getMarche()
{
            $query = TableRegistry::getTableLocator()->get('Marches');
	$query->select([
		'nombre' => $query->func()->count('*'),
		'montantCible' => $query->func()->sum('montant_cible'),
		'montantCommande' => $query->func()->sum('montant_commande'),
		'montantRecep' => $query->func()->sum('montant_receptionne'),
	])
	->group('libelle_marche');
	

	return $query;
}

```

and here is the message I get when I debug the result from my controller:

# Unknown method “func” BadMethodCallException

someone can tell me why i got this error, thanks

---

<div class="post-metadata">

### Author: ![schloter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@schloter](https://discourse.cakephp.org/u/schloter)
#### Post date: [January 24, 2020, 1:55pm UTC](https://discourse.cakephp.org/t/query-in-cakephp-3/7164/2 "2020-01-24T13:55:51Z")

</div>

I found the answer, I forgot the find () in $query = TableRegistry::getTableLocator()-\>get(‘Marches’)-\>find();

```auto

```

---

<div class="post-metadata">

### Author: ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)
#### Post date: [January 25, 2020, 10:26pm UTC](https://discourse.cakephp.org/t/query-in-cakephp-3/7164/3 "2020-01-25T22:26:12Z")

</div>

Can you change title to:

[Solved] Query in cakephp
