Skip to content

Commit 5a280c1

Browse files
committed
Query[Measure[A]] on right hand side of === and <> (provided that A is compatible with left side)
1 parent 11cf8e6 commit 5a280c1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/scala/org/squeryl/dsl/TypedExpression.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ trait TypedExpression[A1,T1] extends ExpressionNode {
117117
def ===[A2,T2](b: TypedExpression[A2,T2])(implicit ev: CanCompare[T1, T2]) = new EqualityExpression(this, b)
118118
def <>[A2,T2](b: TypedExpression[A2,T2])(implicit ev: CanCompare[T1, T2]) = new BinaryOperatorNodeLogicalBoolean(this, b, "<>")
119119

120+
def ===[A2,T2](q: Query[Measures[A2]])(implicit tef: TypedExpressionFactory[A2,T2], ev: CanCompare[T1, T2]) =
121+
new BinaryOperatorNodeLogicalBoolean(this, q.copy(false).ast, "=")
122+
123+
def <>[A2,T2](q: Query[Measures[A2]])(implicit tef: TypedExpressionFactory[A2,T2], ev: CanCompare[T1, T2]) =
124+
new BinaryOperatorNodeLogicalBoolean(this, q.copy(false).ast, "=")
125+
120126
def gt[A2,T2](b: TypedExpression[A2,T2])(implicit ev: CanCompare[T1, T2]) = new BinaryOperatorNodeLogicalBoolean(this, b, ">")
121127
def lt[A2,T2](b: TypedExpression[A2,T2])(implicit ev: CanCompare[T1, T2]) = new BinaryOperatorNodeLogicalBoolean(this, b, "<")
122128
def gte[A2,T2](b: TypedExpression[A2,T2])(implicit ev: CanCompare[T1, T2]) = new BinaryOperatorNodeLogicalBoolean(this, b, ">=")

src/test/scala/org/squeryl/test/schooldb/SchoolDb.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,21 @@ abstract class SchoolDbTestRun extends SchoolDbTestBase {
378378
val se = stringKeyedEntities.insert(new StringKeyedEntity("123", Tempo.Largo))
379379
}
380380

381+
test("EqualCountInSubQuery", SingleTestRun){
382+
val testInstance = sharedTestInstance; import testInstance._
383+
384+
val q =
385+
from(courses)(c =>
386+
where (
387+
//new org.squeryl.dsl.ast.BinaryOperatorNodeLogicalBoolean(1, from(courseSubscriptions)(cs => compute(countDistinct(cs.courseId))).ast, "=")
388+
1 === from(courseSubscriptions)(cs => where(c.id === cs.courseId) compute(countDistinct(cs.courseId)))
389+
)
390+
select(c)
391+
).toList
392+
393+
assert(q.size == 4)
394+
}
395+
381396
test("CountSignatures"){
382397
val testInstance = sharedTestInstance; import testInstance._
383398
val q =

0 commit comments

Comments
 (0)