How to get object at specific index in Persistent Set - Grails -
i have persistent set of objects:
def applicantfiles = applicant.recommendationfiles
how object @ ith element persistent set? tried do
applicantfiles[1] , applicantfiles.getat(1)
neither of work.
sets can't indexed, unordered. if need index collection declare list:
to keep objects in order added , able reference them index array can define collection type list:
class author { list books static hasmany = [books: book] }
with understanding associated table needs column use index. otherwise there's no way preserve ordering. can use indexcolumn specify column use:
by default when mapping indexed collection such map or list index stored in column called association_name_idx integer type in case of lists , string in case of maps. can alter how index column mapped using indexcolumn argument:
static mapping = { matrix indexcolumn: [name: "the_matrix", type: integer] }
http://grails.github.io/grails-doc/2.3.x/ref/database%20mapping/indexcolumn.html
if don't declare instance variable type gorm defaults type set.
Comments
Post a Comment