Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class inheritance in grails

 
charu shila
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I have created my classes like this


class Person{

String email
String password

static constraints={
email(unique:true)

}

}


class JobSeeker extends Person{


}

class Recruiter extends Person{


}


and Bootstrap.groovy is..


class BootStrap {

def init = { servletContext ->


new Jobseeker(email:"aa@bb.com",password:"bbbb").save()
new Recruiter(email:"aa@bb.com",password:"bbbb").save()
}
def destroy = {
}
}



Since emails for Jobseeker and Recruiter are the same, why am I not getting any errors.


Thanks
 
Joseph Swager
Ranch Hand
Posts: 41
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charu,

I'm not an expert in grails, but I think your problem is on the extending
the import will ignore any constraints in the source class (Person) that don't have corresponding properties in the importing classes. I know they are extended from Person, but how are you applying this rule in the extended classes on this constraint.

I had a similar problem and this is the documentation I used to fix it:
http://grails.org/doc/latest/ref/Constraints/Usage.html

Hope That helps or gets you steered toward the correct answer.
Thanks,
Joe Swager
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic