class File {
String name
File parent;
static belongsTo =[parent:File ]
static hasMany = [childrens:File];
static mapping = {
table 'Info_File'
id(generator:'sequence', params: [sequence: 'seq_file'])
parent:[lazy:"true",cascade:"none"]
children joinTable:[name:'children', key:'parent_Id', column:'Id',lazy:"true",inverse:"false",cascade:"none"]
}
static constraints = {
parent(nullable:true)
}
}
Теперь я хочу получить все файлы, родительский идентификатор которых = 1, как я могу это сделать?
Я пытаюсь использовать
def fileList = File.findAllByParent(File.get(1L))
, но он отправит 2 sqlво-первых, получить информацию о родительском файле, которая мне не нужна.
есть ли такой метод, как File.findAllByParentId (1L)
3x
спасибо.
parent{eq('key', 1)}
//sql:from Info_File this_ left outer join Info_File parent_ali1_
//on this_.parent_id=parent_ali1_.id where (parent_ali1_.id=?)
но мне не нужно присоединяться к столу.так что я стараюсь
eq('parent.id',1L)
//it's what i need:
//from Info_File this_ where this_.parent_id=?