Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Last active December 16, 2015 06:49
Show Gist options
  • Save FranckSilvestre/5394135 to your computer and use it in GitHub Desktop.
Save FranckSilvestre/5394135 to your computer and use it in GitHub Desktop.
GORM inheritance simple exemple
package demo
class Cours {
String name
static hasMany = [users:User]
static constraints = {}
}
package demo
class Enseignant extends User {
String matiere
static constraints = {}
}
package demo
class User {
String name
String firstName
static hasMany = [cours:Cours]
static belongsTo = [Cours]
static constraints = {
cours(nullable: true)
}
}
package demo
import org.junit.After
import org.junit.Before
import org.junit.Test
class UserIntegrationTestTests {
@Before
void setUp() {
// Setup logic here
}
@After
void tearDown() {
// Tear down logic here
}
@Test
void testUserAndCourse() {
def prof1 = new Enseignant(name: "toto", firstName: "titi", matiere: "maths")
if (!prof1.save()) {
prof1.errors.allErrors.each { println it }
}
def cours = new Cours(name: "maths")
cours.addToUsers(prof1)
cours.save()
if (!cours.save()) {
cours.errors.allErrors.each { println it }
}
assert Cours.count() > 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment