Skip to content

select bloh with belongs-to works, select blah with has-many does not. #5

@zilti

Description

@zilti

Reproduction:

user2> (declare one, two)
#'user2/two
user2> (defentity one (has-many two {:fk :onid}))
#'user2/one
user2> (defentity two (pk :twid) (belongs-to one {:fk :onid}))
#'user2/two
user2> (exec-raw "create table one(id int auto_increment primary key, oname varchar);
create table two(twid int auto_increment primary key, tname varchar, onid int);")
(0)
user2> (insert one (values [{:oname "blue"} {:oname "red"} {:oname "green"}]))
{:SCOPE_IDENTITY() 3}
user2> (insert two (values [{:tname "hello" :onid 1} {:tname "world" :onid 1}]))
{:SCOPE_IDENTITY() 2}
user2> (select one (with two))
({:two [], :ONAME "blue", :ID 1} {:two [], :ONAME "red", :ID 2} {:two [], :ONAME "green", :ID 3})
user2> (sql-only (select one (with two)))
"SELECT one.* FROM one"
user2> (select two (with one))
[{:ONAME "blue", :ID 1, :ONID 1, :TNAME "hello", :TWID 1} {:ONAME "blue", :ID 1, :ONID 1, :TNAME "world", :TWID 2}]
user2> (sql-only (select two (with one)))
"SELECT two.*, one.* FROM two LEFT JOIN one ON one.id = two.onid"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions