Winston Chen
Winston Chen

Reputation: 6879

SORM: How can I declare many to many relationships?

Is it as strait-forward as this? (Please take a look at interestedLinks in User, and usersInterestedInMe in Link.)

case class User(firstName: String, lastName: String, interestedLinks: Set[Link])
case class Link(name: String, url: String, usersInterestedInMe: Set[User])

If not, how do we declare many to many in SORM?

Upvotes: 1

Views: 203

Answers (1)

Nikita Volkov
Nikita Volkov

Reputation: 43330

Yes, it would be as straight forward as you described, if only your entities didn't form an infinite recursion, which would bring up multiple problems, but, above all, you wouldn't be able to even create such a value, since it's impossible to do in a strict immutable world. Don't believe me? Just throw SORM out of your head and try to instantiate any of your classes with some reasonable values.

So yeah, I'd say either go with rejecting either of interestedLinks: Set[Link] or usersInterestedInMe: Set[User] or model a graph-like relation.

Upvotes: 1

Related Questions