Araq / ormin

Ormin -- An ORM for Nim.
MIT License
152 stars 18 forks source link

Cannot handle join on condition correctly #29

Closed huaxk closed 4 years ago

huaxk commented 4 years ago

Incorrect handling of tables on both sides of the equal sign behind "join on"

  test "query post join person on author == id":
    let postid = 1
    let (author, name) = query:
      select post(author)
      join person(name) on author == id
      where id == ?postid
      limit 1
    check name == persondata[author - 1].name
/home/huaxk/sources/ormin/ormin/queries.nim(897) tforum
/home/huaxk/sources/ormin/ormin/ormin_sqlite.nim(20) dbError

    Unhandled exception: not an error [DbError]
  [FAILED] query post join person on author == id

The produced SQL as follow:

select p1.author, p2.name
from post as p1
inner join person as p2 on p1.author = p1.id
where p1.id = ?
limit 1

The correct SQL should be:

select p1.author, p2.name
from post as p1
inner join person as p2 on p1.author = p2.id
where p1.id = ?
limit 1