"with" embedded results

68 views
Skip to first unread message

Chris Dale

unread,
Jan 14, 2014, 12:53:38 PM1/14/14
to sqlk...@googlegroups.com
If you've got a many-to-many relationship, the result of a with query will look like this:

(select foo (with bar))
=>
{ :id 5
  :bar
  [{:id 1
    :desc "Hello!"}
  {:id 2
   :desc "World!"}]
}

Whereas a simple has-one relationship will result in this:

(select foo (with bar))
=>
{ :id 5
  :desc "Hello!" }

even though desc is a field on bar, not foo. But let's say foo has a relationship with bar and baz, and both bar and baz have a field called "desc".

Korma does handle this case, giving us

(select foo
           (with bar)
           (with  baz))
=>
{ :id 5
  :desc "Hello!"
  :desc_2 "Honey Bunches of Oats!"}

While that certainly works, I find it much more convenient, not to say more semantic, to have nested maps, like we see in the many-to-many relationships. Is there some way to force this? Is this problematic in some way I'm not foreseeing?

That is to say, something like this:

(select foo
           (with bar)
           (with  baz))
=>
{ :id 5
  :bar {:desc "Hello!"}
  :baz {:desc "Honey Bunches of Oats!"}


Dennis Roberts

unread,
Jan 17, 2014, 3:27:49 PM1/17/14
to sqlk...@googlegroups.com
I had a custom version of Korma that did this a while back, but the pull request was never merged in. My code modifications were for a fairly old version of Korma, though, so it would take a while for me to get it working with the latest code. If there’s enough interest in adding this feature, I can take the time to get it working again.

Dennis

--
You received this message because you are subscribed to the Google Groups "Korma" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlkorma+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Scott Walkinshaw

unread,
Jan 27, 2014, 5:02:59 PM1/27/14
to sqlk...@googlegroups.com
I've been experiencing this problem and I'd love a proper solution in Korma core. Baffles me that the solution is to merge the fields into the same map and even rename keys with _2 for example.

Răzvan Rotaru

unread,
Jan 19, 2018, 9:15:42 AM1/19/18
to Korma
I encountered the same "problem", so I guess nothing has changed here.
Reply all
Reply to author
Forward
0 new messages