dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 377 forks source link

many to many association with composite key #541

Closed sm3azr closed 10 years ago

sm3azr commented 10 years ago

I need to do a many to many association where one of the tables has a composite key. The resulting table from the many to many association is already created so I need to change the mergeTable, mergeId and mergeAssocId properties when calling hasMany. The problem is that I am not able to specify two column names for mergeId or mergeAssocId. Is it possible to do this with the current node-orm2 version (v2.1.18)?

sm3azr commented 10 years ago

I found a workaround to this. If one of the tables as columns col1 and col2 as primary keys the solution is to define mergeId as { col1: "dummy_value", col2: "dummy_value" }. Internally the properties of mergeId (col1 and col2) will be converted to the column names so their value doesn't matter. I think a better solution would be to be able to define mergeId as an array and specify the column names there but that doesn't currently work.