object InviteEntity extends Entity[Int, SurrogateIntId, InviteT]("invites") {
val id = key("id") autogenerated(_.id)
val t = column("type") to {
case _: TeamInvite => "TeamInvite"
case _: EventInvite => "EventInvite"
}
val author = {
case team: TeamInvite => manytoone(TeamEntity) to (_.Author)
case event: EventInvite => manytoone(EventEntity) to (_.Author)
}
...
--
You received this message because you are subscribed to the Google Groups "mapperdao" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapperdao+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
CREATE TABLE `invites` (
`id` int(11) NOT NULL,
`author` int(11) NOT NULL,
`receiver` int(11) DEFAULT NULL,
`message` text,
`createdOn` datetime NOT NULL,
`type` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`eventType` varchar(15) NOT NULL,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `teams` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`createdDate` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
//continuation of InviteEntity
def constructor(implicit m: ValuesMap) = m(t) match {
case "TeamInvite" => new TeamInvite(author, receiver, message, time) with Stored {
val id: Int = InviteEntity.id
}
case "EventInvite" => new EventInvite(author, receiver, message, time) with Stored {
val id: Int = InviteEntity.id
}
}
//In models.scala
case class TeamInvite(
Author: Team,
Receiver: User,
message: String = null,
Time: DateTime
) extends InviteT[Team, User]
case class EventInvite(
Author: Event,
Receiver: User,
//Mediator: User,
message: String = null,
Time: DateTime
) extends InviteT[Event, User, User]
CREATE TABLE `invites` (
`id` int(11) NOT NULL,
`team_id` int(11) NOT NULL, -- foreign
key to team table
`event_id` int(11) NOT NULL, -- foreign key to event table
`receiver` int(11) DEFAULT NULL,
`message` text,
`createdOn` datetime NOT
NULL,
`type` varchar(45) NOT NULL,
`eventType` varchar(15) NOT NULL, -- for
EventInvite
`name` varchar(45) NOT NULL, -- for
both EventInvite, TeamInvite
`createdDate`
datetime NOT NULL, -- for TeamInvite
PRIMARY
KEY (`id`)
) ENGINE=InnoDB DEFAULT
CHARSET=utf8;
abstract class InviteT[T <% Inviteable, U <% Invitee] {
val author: T
val receiver: U
val Time: DateTime
val message: String
}
case class EventInvite(
Author: Event,
Receiver: User,
message: String = null,
Time: DateTime
) extends InviteT[Event, User]
On Monday, August 18, 2014 4:58:39 PM UTC-4, Kostas Kougios wrote: <blockquote class="gmail_quote" style="margin: 0...
--
object InviteEntity extends Entity[Int, SurrogateIntId, InviteT]("invites") {
val id = key("id") autogenerated (_.id)
val team = manytoone(TeamEntity) option(_.Author match {
case t: Team => Some(t)
case _ => None
})
val event = manytoone(EventEntity) option(_.Author match {
case e: Event => Some(e)
case _ => None
})
val user = manytoone(UserEntity) option(_.Author match {
case u: User => Some(u)
case _ => None
})
val message = column("message") to (_.message)
val time = column("createdOn") to (_.Time)
def constructor(implicit m: ValuesMap) = {
// m(team) yields Team instead of Option(Team), etc.
//So I cannot match against each to determine what type of subclass I need to construct.
(m(team),m(event),m(user)) match {
case (Some(t: Team), None, Some(u: User)) => new TeamInvite(t, u, message, time) with Stored {
val id: Int = InviteEntity.id
}
}
}
...
message<span
--
...