moigagoo / norm

A Nim ORM for SQLite and Postgres
https://norm.nim.town
MIT License
378 stars 34 forks source link

db.insert(model, force = true) doesn't work as expected #173

Closed Clonkk closed 1 year ago

Clonkk commented 1 year ago

Inserting a model with a specific ID doesn't work.

I added this tests to trows.nim and it fails. I was expecting it to pass.

  test "Insert with forced id":
    var toy = newtoy(137.45)
    toy.id = 134
    print(toy)
    dbConn.insert(toy, force = true)
    check toy.id == 134
    dbConn.delete(toy)

I think this is a regression as we talked about that already in https://github.com/moigagoo/norm/issues/104/

Okay, not a regression, I guess we misunderstood each other. What I meant with insertion with id at non-zero was not just forcing the insertion but forcing the insertion with the given id.

I see from test "Insert row twice" in trows that it was not the intended behaviour. If it's fine with you, I can open a PR changing force behavior when an id is present to insert with the given id field and not just performing the insertion and changing the object id. Conflict are already handled through the conflictPolicy

Clonkk commented 1 year ago

@moigagoo What do you think ? If you're okay with that, I can open the PR in the afternoon

Clonkk commented 1 year ago

We can discuss changes here https://github.com/moigagoo/norm/pull/174