Incorrect value (0) for custom primary keys without auto-increment #3251
-
Sample Code (to reproduce the issue)Any model with custom
Sample migration for such model
Description of problemCreating model with custom primary key and retriving of that primary key lead to incorrect values. Example input for create:
Example output of model of create call:
Example output of model after toJSON call:
Saved data in db contains correct values regadless of output in code. Temporary solution (don't think its right)Removing QuestionHow to deal with such situations? How correctly create custom primary keys are retrive its real value instead of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Since you are self assigning the primary key in the application codebse. You need to use this property to notify Lucid https://docs.adonisjs.com/reference/orm/base-model#static-selfassignprimarykey |
Beta Was this translation helpful? Give feedback.
-
So, its not enought just to mark another column with |
Beta Was this translation helpful? Give feedback.
Since you are self assigning the primary key in the application codebse. You need to use this property to notify Lucid https://docs.adonisjs.com/reference/orm/base-model#static-selfassignprimarykey