instance.getThing() fails on many-to-many with non-primary target key
See original GitHub issueIssue Description
What are you doing?
Here is the link to the SSCCE for this issue: sequelize-sscce#16
Summary:
Ship.belongsToMany(Captain, { through: 'foobar', sourceKey: 'name', targetKey: 'nickname' });
Captain.belongsToMany(Ship, { through: 'foobar', sourceKey: 'nickname', targetKey: 'name' });
// create some records ...
const ship = await Ship.findOne();
console.log(await ship.getCaptains()); // []
What do you expect to happen?
See the SSCCE, ship.getCaptains()
should return something
What is actually happening?
See the SSCCE, ship.getCaptains()
is returning an empty array
Additional context
This refers to the functionality added by #11311
Environment
- Sequelize version: 5.21.1 (latest at the time of this writing)
- Node.js version: v10.16.3
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Specify non-primary target key in belongsToMany association
I am trying to configure a many to many relationship through a joining model. I want to use non-primary string key fields on...
Read more >How to handle many-to-many relationship in Hibernate with ...
I have two objects - Role and Privilege. They have a many-to-many relationship. The code of each object is shown below. import java.io....
Read more >Association Mapping - Doctrine Object Relational Mapper ...
This chapter explains mapping associations between objects. Instead of working with foreign keys in your code, you will always work with references to...
Read more >Models - Django documentation
Each field in your model should be an instance of the appropriate Field class. ... foreign key to the target model (this would...
Read more >Hibernate ORM 5.6.14.Final User Guide - Red Hat on GitHub
BasicType (a org.hibernate.type.Type specialization) instances keyed by a name. That is the purpose of the "BasicTypeRegistry key(s)" column in the previous ...
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
@papb Sure, I can take this one.
I think I have the same problem…
I have these relations:
When i call category.getProducts_children({ limit: 10});
SQL Generated:
SQL Expected:
The sequelize ignore my targetKey: ‘category_id’ and use the primary key.