Doctrine many to many relation join error

Hi folks.

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

Table structure:

  • s_plugin_user_preferred_markets (table of markets that are available to be attached on the users)
    columns: id, name
     
  • s_plugin_user_preferred_markets_mapping (table of markets that are attached to users)
    columns: market_id, user_id

 

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
 

It seems that „where“ function is going directly to shopwares users table, not to s_plugin_user_preferred_markets_mapping.
 

Screenshots:

@irfanh94 schrieb:

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: Association Mapping - Doctrine Object Relational Mapper (ORM)

Kind regards
https://www.digitvision.de

1 „Gefällt mir“

 

@Aquatuning GmbH schrieb:

@irfanh94 schrieb:

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: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html

Kind regards

 

Yes, but I dont want to do that, because I want to get only markets that have certain user_id in s_plugin_preferred_markets_mapping.

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!