Composite keys
aaronbartell opened this issue ยท 11 comments
Have you considered adding a feature for composite key scenarios?
Here is some sample DDL:
CREATE TABLE person(
personId INT(11) NOT NULL,
personName VARCHAR(20) NOT NULL,
PRIMARY KEY(personId)
)
CREATE TABLE language(
languageId INT(11) NOT NULL,
languageName VARCHAR(20) NOT NULL,
PRIMARY KEY(personId)
)
CREATE TABLE personLanguage(
personId INT(11) NOT NULL,
languageId INT(11) NOT NULL,
description VARCHAR(20) NOT NULL,
PRIMARY KEY(personId, languageId),
FOREIGN KEY (personId) REFERENCES person(personId) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (languageId) REFERENCES language(languageId) ON UPDATE CASCADE ON DELETE CASCADE
)
I prefer having an auto incremented primary key and then set the personId and languageId to have unique constraint but this can also be solved.
I would propose adjusting the idProperty to support passing of Array value:
var resultMaps = {
...,
idProperty: ['personId', 'languageId'],
};
// OR
var resultmaps = {
...,
idProperty: [{ name: 'personId', column: 'person_id'}, { name: 'languageId', column: 'language_id' }]
I can create a PR for this, what do you think @nareshbhatia ?
Sounds like a reasonable solution, @FerrielMelarpis. I am assuming that this will only affect the getIdProperty()
function.
I will accept a PR.
@nareshbhatia I created a PR #15 for this feature.
I'm not sure if its the solution you expect.
Please take time to review it and I'll revise further requested changes ๐
Looks great! Thanks for being very meticulous about preserving the intent.
@FerrielMelarpis, I also updated the build tools to a more modern tool chain. Please try it out an let me know if all is working well for you. If yes, I am thinking of releasing this are version 1.0!
@nareshbhatia
Yup looks good.
Sorry for the late reply though haha.
No worries, @FerrielMelarpis. Time to cook up 1.0!
I will try to get it out this weekend. That will give @VividVisions to get his PR in!
@FerrielMelarpis, version 1.0.0 is released! Please test to make sure everything works.
@nareshbhatia Tested and works great! ๐