Goddamn you, grails.


It just takes so much trial-and-error to make any headway!

I have a UserTree. The UserTree has many UserTreeUsers:

class UserTree {
  String ownerId;
  String label;
  List users = [];

  static hasMany = [users: UserTreeUser];

  static mapping = {
    users cascade: 'all-delete-orphan', fetch: 'join', sort: 'userId', lazy: false
  }
}

class UserTreeUser {
  UserTree tree;

  static belongsTo = [tree: UserTree];

  static constraints = {
    tree nullable: false
  }

  static mapping = {
    tree column: 'USER_TREE_ID'
  }
}

It won’t load a user tree object. Why? It’s generating this:

select 
  this_.id as id7_1_, 
  this_.version as version7_1_, 
  this_.LABEL as LABEL7_1_, 
  this_.NODE_ID as NODE4_7_1_, 
  this_.OWNER_ID as OWNER5_7_1_, 
  users2_.USER_TREE_ID as USER4_7_3_, 
  users2_.id as id3_, 
  users2_.users_idx as users6_3_, 
  users2_.id as id4_0_, 
  users2_.version as version4_0_, 
  users2_.PERMISSIONS as PERMISSI3_4_0_, 
  users2_.USER_TREE_ID as USER4_4_0_, 
  users2_.USER_ID as USER5_4_0_ 
from  
  USER_TREE this_ 
  left outer join USER_TREE_USER users2_ on this_.id=users2_.USER_TREE_ID 
where 
  this_.NODE_ID=? 
order by 
  users2_.USER_ID asc

Now ignoring the other columns, you can see that it has decided that the join between User Tree and UserTreeUser is on a column named users_idx. Why? I …

No – that’s not it.

Gaahh! I decalared the user collection to be a List! So it expects there to be an index column! Obviously! What could be more logical?

Riiight.

Lets see if I can get this thing creating a UserTree with a single admin user hanging off it. Thanks, test teddy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: