Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bind domain class by unique name

My Grails app has the following command object

class MyCommand {

    @BindUsing({
        obj, source ->
            User.findByUsername(source.username)
    })
    User user

    // other stuff not relevant to this question
}

The request parameters includes a username which uniquely identifies the User. I've added the @BindUsing annotation in order to bind the user property of the command object to the corresponding User instance. However, after databinding has completed, the user field is null, even though the username parameter is correct. What am I doing wrong?

like image 599
Dónal Avatar asked Apr 12 '26 06:04

Dónal


1 Answers

I don't think this has anything to do with retention policy, dynamic finders, withTransaction or withSession. The issue is that the @BindUsing closure is only triggered for the "user" property if there is a request parameter named "user". The description suggests that there probably isn't one in play in this scenario.

like image 133
Jeff Scott Brown Avatar answered Apr 15 '26 02:04

Jeff Scott Brown