# Doctrine many to many relation join error

**URL:** <https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [7. Juli 2017 um 08:40 UTC](https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767 "2017-07-07T08:40:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![irfanh94](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@irfanh94](https://forum.shopware.com/u/irfanh94)\
**Post date:** [7. Juli 2017 um 08:40 UTC](https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767/1 "2017-07-07T08:40:36Z")

</div>

Hi folks.

I have an ORM model, which have many to many associations to Shopware\Models\User\User  
&nbsp;

Table structure:

- s\_plugin\_user\_preferred\_markets (table of markets that are available to be attached on the users)  
columns: id,&nbsp;name  
&nbsp;
- s\_plugin\_user\_preferred\_markets\_mapping (table of markets that are attached to users)  
columns: market\_id, user\_id

&nbsp;

So, in the custom repository of markets, in the listing method, I am doing a check if the user\_id is given, and if is, I join the table s\_plugin\_user\_preferred\_markets\_mapping to only list the markets that are attached to the user.

And then, there is an error:

[Semantical Error] line 0, col 108 near ‚user\_id = :u‘: Error: Class Shopware\Models\User\User has no field or association named user\_id in vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php on line 63  
&nbsp;

It seems that „where“ function is going directly to shopwares users table, not to s\_plugin\_user\_preferred\_markets\_mapping.  
&nbsp;

Screenshots:

- **Model**  
[https://image.ibb.co/dXxfEa/Screen\_Shot\_2017\_07\_07\_at\_10\_34\_54.png](https://image.ibb.co/dXxfEa/Screen_Shot_2017_07_07_at_10_34_54.png)  
&nbsp;
- **Repository**  
[https://image.ibb.co/nHybnv/Screen\_Shot\_2017\_07\_07\_at\_10\_38\_14.png](https://image.ibb.co/nHybnv/Screen_Shot_2017_07_07_at_10_38_14.png)  
&nbsp;
- **Error**  
[https://image.ibb.co/iRFT0F/Screen\_Shot\_2017\_07\_07\_at\_10\_39\_27.png](https://image.ibb.co/iRFT0F/Screen_Shot_2017_07_07_at_10_39_27.png)

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [7. Juli 2017 um 08:55 UTC](https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767/2 "2017-07-07T08:55:18Z")

</div>

> [@irfanh94 schrieb:](https://forum.shopware.com/profile/26658/irfanh94 "irfanh94")
> 
> It seems that „where“ function is going directly to shopwares users table, not to s\_plugin\_user\_preferred\_markets\_mapping.

Exactly. You can join the users directly without going over your mapping table. Therefor your $mapping attribute should be renamed to $users. More info:&nbsp;[Association Mapping - Doctrine Object Relational Mapper (ORM)](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html)

Kind regards  
[https://www.digitvision.de](https://www.digitvision.de)

---

<div class="post-metadata">

**Author:** ![irfanh94](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@irfanh94](https://forum.shopware.com/u/irfanh94)\
**Post date:** [7. Juli 2017 um 09:10 UTC](https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767/3 "2017-07-07T09:10:00Z")

</div>

&nbsp;

> [@Aquatuning GmbH schrieb:](https://forum.shopware.com/profile/11752/Aquatuning%20GmbH "Aquatuning%20GmbH")
> 
> > [@irfanh94 schrieb:](https://forum.shopware.com/profile/26658/irfanh94 "irfanh94")
> > 
> > It seems that „where“ function is going directly to shopwares users table, not to s\_plugin\_user\_preferred\_markets\_mapping.
> 
> Exactly. You can join the users directly without going over your mapping table. Therefor your $mapping attribute should be renamed to $users. More info:&nbsp;[http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html)
> 
> Kind regards

&nbsp;

Yes, but I dont want to do that, because I want to&nbsp;get only markets that have certain user\_id&nbsp;in s\_plugin\_preferred\_markets\_mapping.

---

<div class="post-metadata">

**Author:** ![irfanh94](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@irfanh94](https://forum.shopware.com/u/irfanh94)\
**Post date:** [7. Juli 2017 um 09:45 UTC](https://forum.shopware.com/t/doctrine-many-to-many-relation-join-error/46767/4 "2017-07-07T09:45:11Z")

</div>

I have found an error.

The model I have used for many to many relation is not Shopware/Models/User/User, its …/Customer/Customer.

Thank you!
