inhibitWhen doesn't work with Enumerations
Leave a comment
Hi, I made a test case for this into src/test/scala/org/squeryl/test/musicdb/MusicDb.scala
https://github.com/hvesalai/Squeryl/commit/1da0018644da2d369ff0456c7bdee48054a94537
https://github.com/hvesalai/Squeryl/commit/1da0018644da2d369ff0456c7bdee48054a94537
on 2011-12-02 14:53 *
By David Whittaker
I think the problem here is with the types involved. In the test case s.genre is a Genre while genreFilter is an Option[Genre], so the conversions go:
Genre -> EnumExpression[Genre]
=== expected EnumExpression[Genre]
Option[Genre].? -> EnumExpression[Option[Genre]
So this can be pretty easily fixed by wrapping change s.genre to Option(s.genre) and causing conversions to EnumExpression[Option[Genre]] on each side.
Max, am I missing something?
Genre -> EnumExpression[Genre]
=== expected EnumExpression[Genre]
Option[Genre].? -> EnumExpression[Option[Genre]
So this can be pretty easily fixed by wrapping change s.genre to Option(s.genre) and causing conversions to EnumExpression[Option[Genre]] on each side.
Max, am I missing something?
on 2011-12-02 17:28 *
By maxime.levesque
Just tried it and it didn't work, here 's something strange :
the ~ forces the implicit conv.
that is the root of the problem,
Should have the type : EnumExpression[Option[Genre]]
Then we could wrap the left side with a Some() ....
BTW ticket #69 if we choose to go that route, will make the wrapping unnecessary,
but the problem of EnumExpression[Option[Option[Genre]]]
the doubling of Option is at the root of this.
val i1 = genreFilter. ~ //the infered type is : EnumExpression[Option[Option[Genre]]]
the ~ forces the implicit conv.
that is the root of the problem,
genreFilter. ~
Should have the type : EnumExpression[Option[Genre]]
Then we could wrap the left side with a Some() ....
BTW ticket #69 if we choose to go that route, will make the wrapping unnecessary,
but the problem of EnumExpression[Option[Option[Genre]]]
the doubling of Option is at the root of this.
on 2011-12-02 17:48 *
By David Whittaker
That's strange because I made the update locally and it does work for me.
Compiles for me and the test passes. I did see that it was creating the double Option before I made the left hand side an option though, so there is probably a rouge implicit somewhere.
test("Enums Inhibit"){
val testInstance = sharedTestInstance; import testInstance._
def listSongs(genreFilter: Option[Genre]) =
from(songs)(s =>
where(Option(s.genre) === genreFilter.?)
select(s)
)
assertEquals(listSongs(Some(Jazz)).size,
songs.where(s => s.genre === Jazz).size,
"expected all Jazz pieces")
assertEquals(listSongs(None).size, songs.size, "expected all songs")
}
Compiles for me and the test passes. I did see that it was creating the double Option before I made the left hand side an option though, so there is probably a rouge implicit somewhere.
on 2011-12-02 18:30 *
By maxime.levesque
Ok got it, it's
where(Some(s.genre) === genreFilter.?)
vs :
where(Option(s.genre) === genreFilter.?)
the strange thing is that they both double the Option[], but only the former one works
So with proper documentation this can be closed
where(Some(s.genre) === genreFilter.?)
vs :
where(Option(s.genre) === genreFilter.?)
the strange thing is that they both double the Option[], but only the former one works
So with proper documentation this can be closed
on 2011-12-02 20:44 *
By David Whittaker
Wow.... yes, that's right, but that's also not what I would expect at all. Whatever the rogue conversion is, it must be applying to Some[Enumeration.Value] and not Option[Enumeration.Value]. That the only explanation I can think of. I'll see if I can track it down.
on 2011-12-17 01:16 *
By maxime.levesque
This is another one that gets solved by #72
I just tried it and it worked out of the box.
I published a sneak preview : "org.squeryl" %% "squeryl" % "0.9.5-extended-types-poc".
I just tried it and it worked out of the box.
I published a sneak preview : "org.squeryl" %% "squeryl" % "0.9.5-extended-types-poc".