-
Hello everyone, Sorry if this is not the right way to ask but I don't know how to configure these relationships anymore. I have cards and turns in a n:m relationship, 1 card belongs to 1 turn and turns have many cards. For the n:m relationships I have had no problem in the configuration but I keep getting the error when I try to create the relationship between cards and turns:
Also, in the database, after migration, both tables are binded in the right way. Turn model:
Card model:
Migration defining relationship:
When I try to asign a Turn to a Card or viceversa in, for example, a seeder, i get the error. Example seeder code would be:
I am quite lost and do not see what could be causing the error. I have tried what other people have asked but have not been able to get it to work for me either. Thanks in advance Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello, have you read pages about these relations? And can you provide a schema model using DrawSQL to understand the purpose? |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering, @Barbapapazes Summarizing the relationship, the diagram would look like this https://drawsql.app/s-28/diagrams/minimal/embed 1 turn -> many cards (the rest of the relationships (many to many) are not relevant to this error and, also, are working great) I have read the documentation and I have called the attributes (as far as I have seen and if I am not mistaken) in the same way as they are called in the examples, right? If i do some console.log with |
Beta Was this translation helpful? Give feedback.
-
Oh... I figured out what was going on. It doesn't say it in the documentation, but you need to also add the corresponding attribute to the relationship, not just the relationship itself. As in the migration it is done together I hadn't thought it was necessary. So it has been fixed with this code in the "n" relationship, the one with
|
Beta Was this translation helpful? Give feedback.
Oh... I figured out what was going on. It doesn't say it in the documentation, but you need to also add the corresponding attribute to the relationship, not just the relationship itself.
As in the migration it is done together I hadn't thought it was necessary.
So it has been fixed with this code in the "n" relationship, the one with
BelongsTo
defined (I leave it here in case someone can use it):