-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defing models with foreign entities #7239
Comments
Hi, you must use Pointer for |
Why isnt it that way in the doc ?? https://gorm.io/docs/has_one.html
|
And I still have errors when doing this:
|
You still have errors because: |
Why not in the parent structure ? |
Imagine the raw query in SQL:
the child linked to parent => child has parent_id Now, if any parent has too many children, you have to use an array of children in the parent structure. |
well its the parent that should hold the child_id and not the child that should hold the parent_id. So I dont get your example |
Your Question
I have an entity
RealWorkout
which possesses 1Workout
which is supposed to act as a Template.In order to have my code working I have to have 3 fields:
Workout
WorkoutID
TemplateID
2 is needed because even with a model without
WorkoutID
I getworkout_id
field in my DB and I sometimes have to set it usingWorkoutID
3 is needed because otherwise at compilation I get the following error:
[error] invalid field found for struct gin-app/misc.RealWorkout's field Template: define a valid foreign key for relations or implement the Valuer/Scanner interface
The document you expected this should be explained
I am not a native english speaker but I did not understand what you excepted from me in this chapter :(
Expected answer
Having all those 3 fields seem very repetitive and error prone, ideally it should be possible to only have
Template Workout
? I do not get why I also need an ID field and even more why it has to have specific names, I searched through this and did not find an answer: https://gorm.io/docs/belongs_to.htmlAm I doing my model wrong ? What is really needed ? What do I need that ID field even though it is a repetition of my Workout.ID
The text was updated successfully, but these errors were encountered: