gorm - Cant access grails one to many relationship data -
i asking dump question new 1 grails.
i have 2 domain school , classes
class school { static hasmany = [ classes: classes ] }
and
class classes { static belongsto = [school] }
now can not data - if 's' school have c1,c2,c3 classes check 2 ways get.
1. classesinstancelist = classes.findallbyschool(s)
it returns null;
2. classesinstancelist = s.getclasses();
it returns follwing error message
message: failed lazily initialize collection of role: com.test.school.classes, no session or session closed
please suggest can do. stucked . why first 1 not work please explain someone.
you can create reference classes
domain school , search school object.
class classes { static belongsto = [school:school] static constraints = {} } class school { static hasmany = [ classes: classes ] static constraints = {} string tostring(){"$id"} }
test:
def s = new school() def c = new classes() s.addtoclasses(c) s.save(flush:true) println classes.findallbyschool(s)
this should give classes
related school
.
Comments
Post a Comment