Updated Question After some further debugging I’ve updated this question to be more accurate on the actual problem.
I have a trait I’ve defined to do a basic security check but every time I want to run a DB query it throws a Cannot operate on a closed connection!!! error.
Code below:
trait SecureAPI {
self:Controller =>
@Before
def checkKey(key:String)
models.Account.getByKey(key) match {
case account:Account => {
renderArgs += "account" -> accountId
Continue
}
case _ => Forbidden("Key is not authorized.")
}
}
The getByKey throws the DB error. In my controllers, I’m adding Squeryl as a trait, but how would I apply that in another trait so I can continue to run queries? Or am I just not approaching this properly? Thanks.
I got deeper into different readings and credit for this one goes to this post here: http://www.alvarocarrasco.com/2010/12/i-have-settled-on-new-platform-for.html
I had to use Squeryl to bind the session to the current thread. So to make the above code work, I had to add in
SessionFactoryEverything now queries, just need to work out a few bugs. I’ll update the answer if I discover any more caveats.