首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

GRAILS belongsTo hasMany 查询有关问题

2012-11-10 
GRAILS belongsTo hasMany 查询问题这个bug已经在1.1的正式版本中修复。举个例子:class Author {static has

GRAILS belongsTo hasMany 查询问题
这个bug已经在1.1的正式版本中修复。

举个例子:
class Author {
  static hasMany = [books:Book]
}
class Book {
  static belongsTo = [author: Author]
}

查询Author:
def criteria = Author.createCriteria()
def list = criteria {
   //conditions
}
list.each { author->
  author.books.each{
  }
}

在author.books.each这一步就会导致book的更新(version会变化,有时候会导致乐观锁错误)
改成如下方式可避免:
def books = Book.findAllByAuthor(author)
books.each {
}

热点排行