Last active
August 29, 2015 13:56
-
-
Save robhinds/8825662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Entity people = schema.addEntity("People"); | |
people.addIdProperty(); | |
people.addStringProperty("name").notNull(); | |
people.addStringProperty("emailAddress").notNull(); | |
/* | |
* The entity for an email | |
*/ | |
Entity email = schema.addEntity("Email"); | |
email.addIdProperty().getProperty(); | |
email.addStringProperty("subject").notNull(); | |
email.addStringProperty("body"); | |
/* | |
* A Relation entity - this captures the join table | |
* between email and people | |
*/ | |
Entity emailPeople = schema.addEntity("EmailPeople"); | |
emailPeople.addIdProperty(); | |
/* | |
* Add the emailId to the join table and setup the FK relationship | |
*/ | |
Property emailId = emailPeople.addLongProperty("emailId").notNull().getProperty(); | |
ToMany emailToPeople = email.addToMany(emailPeople, emailId); | |
emailPeople.addToOne(email, emailId); | |
emailToPeople.setName("recipients"); | |
/* | |
* Add the recipient ID (people ID) to the join table and setup the FK relationship | |
*/ | |
Property recipientId = emailPeople.addLongProperty("recipientId").notNull().getProperty(); | |
ToMany recipientsToEmail = people.addToMany(emailPeople, recipientId); | |
emailPeople.addToOne(people, recipientId); | |
recipientsToEmail.setName("emailsRecieved"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment