Summary: I am pulling a list of user IDs from a members transaction table that is then used to generate a list of users from the database. This is then used to generate JSON sent to a page that lists users associated with an account.
Background: Scala code using Squeryl on Play! Framework
The Error: value id is not a member of Option[models.User]
when mapping the users to the JSON generator
The Code: Here's code being used in succession to finally generate the JSON
def memberIds(accountId: Long) = { from(DB.members)(m =>
where(m.accountId === accountId)
select (m)).map(_.userId).toSet
}
def membersToAccount(id: Long) = {
memberIds(id).map( i => models.User.get(i))
}
def listMembers(accountId: Long) = {
Json(generate(Account.membersToAccount(accountId)
.map(user => Map(
"id" -> user.id,
"name" -> user.name,
"username" -> user.username
))))
}
The Confusion: the User class contains an id val that looks like case class User(
val id: Long, etc.
I'm confused as to why it would create this error. Is it a problem with syntax or where I am mapping the users? Thanks!