Als Ergebnis trying to make a Slick query more readable, ich habe diese Abfrage Konstruktor, der wäre gleichbedeutendWarum sind diese beiden Slick-Abfragen nicht gleichwertig?
val q = Users.filter(_.id === userId) join People on {
case (u, p) => u.personId === p.id
} joinLeft Addresses on {
case ((u, p), a) => p.addressId === a.id
} joinLeft Businesses on {
case (((u, p), a), b) => p.businessId === b.id
} joinLeft Addresses on {
case ((((u, p), a), b), ba) => b.flatMap(_.addressId) === ba.id
} map {
case ((((u, p), a), b), ba) => (p, a, b, ba)
}
und dieses Ich dachte, funktioniert, aber nicht funktioniert:
val q = Users.filter(_.id === userId) join People joinLeft Addresses joinLeft Businesses joinLeft Addresses on {
case ((((u, p), a), b), ba) =>
u.personId === p.id &&
p.addressId === a.flatMap(_.id) &&
p.businessId === b.flatMap(_.id) &&
b.flatMap(_.addressId) === ba.id
} map {
case ((((u, p), a), b), ba) => (p, a, b, ba)
}
Die zweite scheint eine Liste von Profilen zurückgeben, die mehr als das Zielprofil enthalten.
Warum sind sie nicht gleich?
Die "gleichwertig" SQL (IE das Ziel dieser Konstruktion) ist:
select p.*, a1.*, b.*, a2.* from Users u
innerJoin People p on (u.personId == p.id)
leftJoin Addresses a1 on (p.addressId == a1.id)
leftJoin Businesses b on (p.businessId == b.id)
leftJoin Addresses a2 on (b.addressId == a2.id)