Closed basz closed 9 years ago
Did you change the mapping config entity_field_name? https://github.com/TomHAnderson/zf-oauth2-doctrine/blob/master/config/oauth2.doctrine-orm.global.php.dist#L91
yes I tried to change every instance (4) of 'entity_field_name'
Are you using the default ZfcUserDoctrine entity definition (use_default_entities)? If you're not will you post your User entity XML [or annotation]?
Here's my custom entity def using ZfcUserDoctrine: https://github.com/TomHAnderson/apigility-oauth2-doctrine-skeleton/blob/master/module/Db/config/orm/Db.Entity.User.dcm.xml
enable_default_entities is false. I have an entity that extends ZfcUser\Entity\User (https://gist.github.com/basz/7adb871fa9e987b7b308) and I assume that ZfcUserDoctrine handles the actual field definitions (which it does, the create sql for user is correct). I currently only add a Timestampable trait as extra fields.
I noticed that your Db.Entity.User.dcm.xml does not have this 'column="user_id"' defined, so you will not encounter this problem.
I have also seen such an issue before with Doctrine but I can't remember how and what now anymore... :-/
hmm, what i now do is not extend ZfcUser\Entity\User and add those annotations to my Entity making sure the PK column is named 'id'. Avoiding this issue...
I believe this is an issue with Doctrine and not with your module or zfc user (doctrine) as I recall to have encountered this before.
thanks for your help! Quick unrelated question. Can I rename the table names via configuration?
No, you can't rename the tables unless you create your own set of entity definitions. You could copy the existing XML and put them in another module and keep the references to the entities the same then disable default entities (which really means disable default metadata).
The root cause of your problem is you're not using the right namingStrategy in your ClassMetadata. The namingStrategy by default calls the primary key 'id'. I think a longer term answer is the mapping array for the mapManyToOne calls need to be extended to allow additional mapping info.
To fix your problem this way you would add joinColumns:
'refresh_token_entity' => array(
'entity' => 'ZF\OAuth2\Doctrine\Entity\RefreshToken',
'field' => 'refreshToken',
'join_columns' => array(
array(
'name' => 'user_id',
'referencedColumnName' => 'user_id',
),
),
),
a I see (sort of :-))
Renaming is possible it seems https://gist.github.com/basz/f6160c207c81742b949b
Here's a fix for your issue. Use is documented in the README.md in the PR https://github.com/TomHAnderson/zf-oauth2-doctrine/pull/19
Please give it a try.
In combination with ZfcUser and ZfcUserDoctrine I'm getting incorrect CONSTRAINTS
note the REFERENCES user (id) vs REFERENCES user (user_id)
instead of