Skip to content

Instantly share code, notes, and snippets.

@robhinds
Last active August 29, 2015 13:56
Show Gist options
  • Save robhinds/8825662 to your computer and use it in GitHub Desktop.
Save robhinds/8825662 to your computer and use it in GitHub Desktop.
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