# How to use PropertyName and ClassName

**URL:** <https://discourse.cakephp.org/t/how-to-use-propertyname-and-classname/2070>\
**Category:** Need Help\
**Created:** [February 14, 2017, 2:46pm UTC](https://discourse.cakephp.org/t/how-to-use-propertyname-and-classname/2070 "2017-02-14T14:46:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndgAlainB](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@ndgAlainB](https://discourse.cakephp.org/u/ndgAlainB)\
**Post date:** [February 14, 2017, 2:46pm UTC](https://discourse.cakephp.org/t/how-to-use-propertyname-and-classname/2070/1 "2017-02-14T14:46:40Z")

</div>

Hello,

I want my `SitesTable` be associated to `Languages` with 2 kind of associations:  
A site can speak several languages at deck and can speak several languages for the visits.  
So I created 2 join tables `sites_reclanguages` and `sites_vislanguages`

And so in `SitesTable` I wrote the following associations:

```
$this->belongsToMany('Reclanguages', [
    'joinTable' => 'sites_reclanguages',
    'className' => 'Languages'
]);

$this->belongsToMany('Vislanguages', [
	'joinTable' => 'sites_vislanguages',
    'className' => 'Languages'
]);

```

And I expected to be able to write:

```
$sites = $this->Sites->find()
             ->contain([
                 'Reclanguages',
                 'Vislanguages
            ])
            ->where([...])
            ->all();

```

But it seems not to be the right way.

How to do it?

---

<div class="post-metadata">

**Author:** ![ndgAlainB](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@ndgAlainB](https://discourse.cakephp.org/u/ndgAlainB)\
**Post date:** [February 14, 2017, 2:59pm UTC](https://discourse.cakephp.org/t/how-to-use-propertyname-and-classname/2070/2 "2017-02-14T14:59:47Z")

</div>

I found!

The association must be declared that way:

```
$this->belongsToMany('RecLanguages', [
    'joinTable' => 'sites_reclanguages',
    'className' => 'Languages',
    'propertyName' => 'Reclanguages'
]);

$this->belongsToMany('Vislanguages', [
	'joinTable' => 'sites_vislanguages',
    'className' => 'Languages',
    'propertyName' => 'Vislanguages'
]);

```

And the query will be:

```
$sites = $this->Sites->find()
         ->contain([
             'Reclanguages',
             'Vislanguages
        ])
        ->where([...])
        ->all();
```
