You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hasMany's doesn't support the targetKey parameter option, and automatically joins VisitorStats.statistical_id on Property.id when I query. I expected the targetKey property to work like at a belongsTo association.
Is it possible to change the target key using hasMany? If not, how should I represent this 1:m association?
Reacted by Brad Decker, Eric Koslow, Tomáš Horáček, Pavel Evstigneev, Felix Becker, Andrew Holsted, Nate Silva, Justin Pincar, Anurag Gupta, Peter Slivka and 8 more
I ended up having to use a raw SQL query, otherwise I would have had to invert the true object model to make the query work. So, it's possible to get the job done, but my premise is that an ORM ideally models logically the object tree as it should exist.
@PyroSA BelongsTo is the only one it works for, are you saying it no longer works, or are you saying it doesn't work from the HasOne side (which it never has)?
@PyroSA We have a test for that feature, so it should work - Please open a seperate issue with a reproduceable case since this issue deals with expanding the feature.
@mickhansen - I brought it up because #4269 was closed and referred to this feature. If it's considered a separate issue, can't that issue be re-opened?
Is there any chance of this getting addressed anytime soon. We have a project using Heroku Connect with Salesforce. Salesforce tables join using the 'sfid' field which is not an integer primary key. I really need to be able specify a 1 to many relationship with hasMany setting the targetKey to this field instead of the primary key. Just seems strange to me that this has been sitting out so long.
@janmeier Thanks, I guess I missed that. That said this PR seems to address all the issues. Is it possible to just get the conflict in the changelog fixed so this can get merged? #6652
Reacted by Kristoffer K Larsen, Matt Turner, Igor Shevelyov, Don Townsend, JSantos, Joost van Berkel, bigmurry, Michał Bury, Sebastian "Sebbie" Silbermann, Mitchell Garcia and 34 more
This example from the pr worked for me. I wish the documentation would be updated correctly. It took a while to figure it out.
Reacted by Miloš Jovac, Piotr Gulbis, Michael Schmerbeck, Serdar, Kilian Brachtendorf, Divyanshu Kalra, Piotr Sko, Ali Hesari, ronakdev156, Dilip Suthar and 7 more
Reacted by Miloš Jovac, Michael Schmerbeck, Divyanshu Kalra, Dilip Suthar, Carlo Patti, Danil Sadovnikov and Isaac Souza
Reacted by Miloš Jovac, Michael Schmerbeck, syldor, Serdar, Divyanshu Kalra, Carlo Patti, Alican Sahin, Danil Sadovnikov, otsuka and Isaac Souza
Reacted by Michael Schmerbeck, Divyanshu Kalra, Carlo Patti, Danil Sadovnikov and Isaac Souza
Activity
janmeier commentedon Aug 5, 2015
targetKeyis not yet supported for hasMany[-]hasMany association always joins on primary key[/-][+]targetKey for hasMany and hasOne[/+]treejanitor commentedon Aug 29, 2015
This seems like a very useful modeling feature, especially for legacy databases.
sijmenvos commentedon Aug 31, 2015
I agree +1
treejanitor commentedon Aug 31, 2015
I ended up having to use a raw SQL query, otherwise I would have had to invert the true object model to make the query work. So, it's possible to get the job done, but my premise is that an ORM ideally models logically the object tree as it should exist.
PyroSA commentedon Sep 7, 2015
As per #4269, it is not working for HasOne/BelongsTo relationships either.
The ForeignKey works, but it still uses .id for the include statement.
mickhansen commentedon Sep 7, 2015
@PyroSA BelongsTo is the only one it works for, are you saying it no longer works, or are you saying it doesn't work from the HasOne side (which it never has)?
PyroSA commentedon Sep 7, 2015
It does not work for the BelongsTo in our case either.
Not my project, but off the top of my head it would look like:
Not sure of the order (Ta/Tb) but:
Tb.findAll include: [Ta]then tries to join on
Ta.id == Tb.guidinstead ofTa.guid == Tb.guidI can confirm the exact sequence if it's unclear.
guids are stored as strings in this case.
PyroSA commentedon Sep 7, 2015
@mickhansen - Tried to clarify above
mickhansen commentedon Sep 7, 2015
@PyroSA We have a test for that feature, so it should work - Please open a seperate issue with a reproduceable case since this issue deals with expanding the feature.
PyroSA commentedon Sep 7, 2015
@mickhansen - I brought it up because #4269 was closed and referred to this feature. If it's considered a separate issue, can't that issue be re-opened?
If not I can create a new issue.
guigrpa commentedon Sep 8, 2015
I have opened a new issue, as @mickhansen suggested: #4455
mickhansen commentedon Sep 8, 2015
@PyroSA that issue is about HasOne, not Belongsto :)
colegleason commentedon Sep 16, 2015
Hey, I also have legacy tables and would love this feature. Is there any good workaround in the meantime?
19 remaining items
V4 Fix sourceKey for hasMany, issue: #4258 (#7113)
LoneWolfPR commentedon Jan 23, 2017
Is there any chance of this getting addressed anytime soon. We have a project using Heroku Connect with Salesforce. Salesforce tables join using the 'sfid' field which is not an integer primary key. I really need to be able specify a 1 to many relationship with hasMany setting the targetKey to this field instead of the primary key. Just seems strange to me that this has been sitting out so long.
janmeier commentedon Jan 23, 2017
@LoneWolfPR it's been sitting so long because no one has taken the time to finish the code and tests.
As Felix mentions, the code is actually there, some one just needs to pick it up and add some tests
LoneWolfPR commentedon Jan 23, 2017
@janmeier Thanks, I guess I missed that. That said this PR seems to address all the issues. Is it possible to just get the conflict in the changelog fixed so this can get merged? #6652
V3 Fix sourceKey for hasMany, issue: #4258 (#6652)
V4 Fix sourceKey for hasMany, issue: sequelize#4258 (sequelize#7113)
joe-angell commentedon May 11, 2017
How about
sourceKeyforhasOne?mlyticsAdamGe commentedon Feb 2, 2018
To describe the relationship
belongsTo --->use targetKey to set the foreigner key from
hasMany --->use sourceKey to set the foreigner key from
or it will bind to the primary key
philipimperato commentedon Apr 3, 2018
Is Sequelize still being actively developed? There a bunch of issues that have are stale.
eggerand13 commentedon Nov 28, 2018
Maybe this information should be added to the legacy database handling in the documentation (http://docs.sequelizejs.com/manual/advanced/legacy.html)
Do I understand correctly that a fix for v4 has been commited but not been merged? mkaufmaner@1879d39
williamkwao commentedon May 21, 2019
This example from the pr worked for me. I wish the documentation would be updated correctly. It took a while to figure it out.
piotrgulbis commentedon Jun 29, 2019
This fixed the issue for me as well. Would be very helpful to update the docs!
dilipsuthar97 commentedon Apr 13, 2021
Thanks @williamkwao, You saved my day
cpatti97100 commentedon Apr 13, 2021
please someone who tried this out update the docs :) that would be really helpful for the future!