dresende / node-orm2

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

Multiple hasOne relationship causes wrong Insert operation #680

Open zBuffer opened 8 years ago

zBuffer commented 8 years ago

Given

var CapturedImage = db.define("CapturedImage", {
    ImageID: { type: "text", index: true },
    CreationDate: { type: "date", index: true },
    Path: String,
});

var VRecord = db.define("VRecord", {
    EntryID: { type: "text", index: true },
    CaptureDateTime: { type: "date", index: true },
});

VRecord.hasOne("FullImage", CapturedImage);
VRecord.hasOne("CroppedImage", CapturedImage);

then

            models.VRecord.create({
                EntryID: ...,
                CaptureDateTime: ...,
                FullImage: {...},
                CroppedImage: {...},
            }

will result in 2 separate insertions into CapturedImage (correct behavior), but the reference from the VRecord row points to the (same) latter CapturedImage record instead of pointing to their assigned records.

Creating CapturedImage using create() beforehand will not yield this issue.

Using sqlite.