Last active
December 16, 2015 06:49
-
-
Save FranckSilvestre/5394135 to your computer and use it in GitHub Desktop.
GORM inheritance simple exemple
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
package demo | |
class Cours { | |
String name | |
static hasMany = [users:User] | |
static constraints = {} | |
} |
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
package demo | |
class Enseignant extends User { | |
String matiere | |
static constraints = {} | |
} |
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
package demo | |
class User { | |
String name | |
String firstName | |
static hasMany = [cours:Cours] | |
static belongsTo = [Cours] | |
static constraints = { | |
cours(nullable: true) | |
} | |
} |
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
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