Mapping extra properties on linking table for manytomany relationship?

Skip to first unread message

Jun 30, 2014, 11:57:22 AM6/30/14


Is there any way I can map properties of a relationship to one of the involved entities?

For instance

table Person (
    id int
    name string
    eventId int
table Event (
    id int
    eventName string
    someOtherProps string
table Person_Event (
    personId int
    eventId int
    isPresent boolean //this is the extra property, notes whether the person is present at the event
    primary key(personId, eventId)
    foreign key(personId) references Person(id)
    foreign key(eventId) reference Event(id)

and then have it map so that when I create my EventEntity

object EventEntity extends Entity[Int, SurrogateIntId, Event] {
     val id = key("id") autogenerated (
     val name = column("eventName") to (
     val other = column("someOtherProps") to (_.other)
     val isPresent =  ??? //map the extra property on the linked table here
     val persons = manytomanyreverse(PersonEntity) to (_.persons)


Konstantinos Kougios

Jun 30, 2014, 3:02:30 PM6/30/14
Hi, it can be possible (I think, I haven't got any test case similar to this). But first, what would your domain model classes look like? And you got Person.eventId and Person_Event.eventId, what's up with both those?
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
For more options, visit

Jun 30, 2014, 3:14:19 PM6/30/14

My apologies, I hastily typed out that code and I realize it doesn’t make much sense now :)

First, a description:
Users can attend multiple Events, and Events can contain multiple Users. The relationship between the two is many-to-many. I would like to include extra information about each individual relationship between an Event and a User though — such as whether the User is present at the Event (isPresent)
Here are more domain objects

class User(val id: Int, val email: String, val createdDate: DateTime, val events: Set[Event]) {
class Event(val id: Long, val name: String, val eventType: JoinType.Value, val description: EventDetails, val users: Set[User]) {

Initially I thought I would like to have an isPresent field for each Event but after doing some research this does not seem possible(and really doesn’t make sense), what I really trying to achieve is described here, Mapping a Join Table with Additional Columns.

Konstantinos Kougios

Jun 30, 2014, 3:19:42 PM6/30/14
Yes I think having an Event.isPresent doesn't make sense since it couples the Event with a specific User.

So creating an intermediate entity as  described in your link seems to be the best approach as both User and Event should be decoupled from each other.
Reply all
Reply to author
0 new messages