Setting a relationship's foreign key as tableName_primaryKey doesn't work with snakecased names
See original GitHub issueAccording to the docs http://adonisjs.com/docs/4.0/relationships#_has_many
Quick example
cars() {
return this.hasMany('App/Models/Cars', 'id', 'user_cars_user_id')
}
This relation is going to look into user
table because the string is split by underscores, hence you can’t target tables with underscores in its name. Same happens with foreign key columns.
Because of that, the delimiter must be a dot: 'user_cars.user_id'
(in the form tableName.fieldName
), right?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Setting a relationship's foreign key as tableName_primaryKey ...
This relation is going to look into user table because the string is split by underscores, hence you can't target tables with underscores...
Read more >3 common foreign key mistakes (and how to avoid them)
Foreign key constraints are important to any SQL database, but they can also cause problems if they're not implemented correctly.
Read more >Can't set foreign key relationship - mysql workbench
The thing is when I enter a FK and choose a reference table I can't pick a referenced column. I can't click the...
Read more >Create Foreign Key Relationships - SQL Server | Microsoft Learn
This article describes how to create foreign key relationships in SQL Server by using SQL Server Management Studio or Transact-SQL.
Read more >Running a relationship analysis) - IBM
A relationship analysis identifies pairs of foreign keys and primary keys. Use this information to determine how data assets can be joined. Run...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe you didn’t read it properly. As per the docs
The convention to use the
foreignKey
is based on thetableName_primaryKey
. However, you can define your own customforeignKey
.But it doesn’t say that your
foreignKey
will be parsed to pull the tablename and then primaryKey.Why the hell on the planet a Model will use a different table using Relationship.
Also when you think it’s a confusion on docs or implementation. Then you must ask in a clarification tone, instead of declaring everything as a bug.