Hi there !
I'm begginning with Grails,
This is my first domain class : "Batiment" who has many "Salle"
This is my second domain class : "Salle" who has one "Batiment"
And this is my Bootstrap of test :
The problem is that :
"Batiment b = Batiment.findByNom("U2")" returns the correct "Batiment"
but
"Salle s = Salle.findByNom("202")" returns null
and "202" exists...
I think it's a problem with the "join" on "Batiment"...
That problem makes me crazy since one week
yet, all "Salle" appear in my web application and "202" is one of them
I try also :
But same results...
If someone can help me...
Thanks
I'm begginning with Grails,
This is my first domain class : "Batiment" who has many "Salle"
Code:
class Batiment {
String nom;
static hasMany = [salles : Salle]
static constraints = {
nom (blank : false, unique : true)
}
Batiment(String nom){
this.nom = nom
}
String toString(){
return "$nom"
}
}
This is my second domain class : "Salle" who has one "Batiment"
Code:
class Salle {
String nom;
int capacite;
static hasOne = [batiment : Batiment]
static hasMany = [reservations : Reservation]
static belongsTo = [batiment : Batiment]
static constraints = {
nom (blank : false, unique:['batiment'])
capacite (blank : false, min : 1)
}
Salle(String nom, int capacite){
this.nom = nom;
this.capacite = capacite;
}
String toString() {
return "$nom"
}
}
And this is my Bootstrap of test :
Code:
def init = { servletContext ->
// Création des Batiments de tests
List<String> listeNomBatiments = [
"1A", "2A", "3A", "4A",
"1TP1", "1TP2", "1TP3", "1TP4",
"1R1", "1R2", "1R3", "1R4",
"U1", "U2", "U3", "U4"
]
listeNomBatiments.each {
nom -> new Batiment(nom).save(failOnError: true);
}
// Création des Salles de tests
Batiment.findByNom("U1")
.addToSalles(new Salle("201",30))
.addToSalles(new Salle("202",30))
.addToSalles(new Salle("203",30))
.addToSalles(new Salle("204",30))
.addToSalles(new Salle("205",30))
.addToSalles(new Salle("206",30))
.addToSalles(new Salle("207",30))
System.out.println("Batiment :")
Batiment b = Batiment.findByNom("U2")
if(b != null){
System.out.println(b) // OK : "U2"
}
else{
System.out.println("null !")
}
System.out.println("Salle :");
Salle s = Salle.findByNom("202")
if(s != null){
System.out.println(s)
}
else{
System.out.println("null !")
}
The problem is that :
"Batiment b = Batiment.findByNom("U2")" returns the correct "Batiment"
but
"Salle s = Salle.findByNom("202")" returns null
and "202" exists...
I think it's a problem with the "join" on "Batiment"...
That problem makes me crazy since one week
I try also :
Code:
def salles = Salle.executeQuery(
'from Salle s where s.nom = :nomSalle',
[nomSalle: "202"]
)
But same results...
If someone can help me...
Thanks