For your custom function, the last argument must be an Iterable, not the StringExpression itself,
you can use a Seq here :
class GroupConcat(e: StringExpression[String], m:OutMapper[String])
extends FunctionNode[String]("group_concat", Some(m),
Seq(e)) with StringExpression[String] {
override def doWrite(sw: StatementWriter) = {
sw.write(name)
sw.write("(")
sw.writeNodesWithSeparator(args, ",", false)
sw.write(" separator ',')")
}
}
You were probably mislead by the example here :
http://squeryl.org/custom-functions.htmlwhich had this error, i've corrected it, my appologies...
Now for this query :
select m.*, group_concat(mtu.userId separator ',') as recipients, mtu.isRead, mtu.isFlagged, mtu.isDeleted
from
message_to_user mtu, message m where
mtu.messageId in (
select messageId from message_to_user where userId = 3 and isSender = 0 and isDeleted = 0
)
and mtu.isSender = 0 and
m.id = mtu.messageId
group by
m.id
It's not valid SQL, perhaps MySql does something with it, but most DBs won't accept it,
the
1) selected colums must all be included in the group by columns
2) additional colums must be inside aggregate functions
this would be valid :
select m.i, group_concat(mtu.userId separator ',') as recipients,
this also :
select m.i, group_concat(mtu.userId separator ',') as recipients, sum(mtu.isRead), sum(mtu.isFlagged), sum(mtu.isDeleted)
also, grouping on content is suspicious :
groupBy(
m.id, m.subject, m.content))
if your trying to minimize DB roundtrips, you could select something like :
select m.i, group_concat(mtu.userId separator ',') as recipients,
and then join this with the message table (with the ke
m.id).
Hope that helps...
ML