@Mixin and domain objects

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

@Mixin and domain objects

Sonny To
I have a class src/groovy/User.groovy used as a Mixin

class User {
    String firstName
    String lastName
    String email
}

I'd like to mixin this class with a @Mixin annotation in my domain classes:

@Mixin(User)
class Player{
   String foo
}

@Mixin(User)
class GameAdmin{
    String bar
}

However this does not seem to be working. The User properties do not get created in the DB tables. Is this a bug or is this the expected behavior? I think domain objects should be able to handle mixin

I change this to an inheritance relationship but I do not want to do that.
Reply | Threaded
Open this post in threaded view
|

Re: @Mixin and domain objects

Marcin Gryszko-2
Groovy mixins don't copy properties into the mixee class. You can see them as a separate class 'magically' connected to the mixee class.

Use a debugger and step into the domain class code to see how mixin and mixee are connected together.
Reply | Threaded
Open this post in threaded view
|

Re: @Mixin and domain objects

tudor.malene
In reply to this post by Sonny To
I think what you want to do is this:

class Player {
    @Delegate User user  = new User()
    String foo
    static embedded = ['user']
    static transients = ['firstName', 'lastName', 'email' ]
}

but be sure to run a 'clean' before, so that you don't get in trouble with @Delegate and the gorm enhancer
Reply | Threaded
Open this post in threaded view
|

Re: @Mixin and domain objects

Sonny To
In reply to this post by Marcin Gryszko-2
good info! thanks Marcin


On Mon, Feb 18, 2013 at 10:33 AM, Marcin Gryszko <[hidden email]> wrote:
Groovy mixins don't copy properties into the mixee class. You can see them as a separate class 'magically' connected to the mixee class.

Use a debugger and step into the domain class code to see how mixin and mixee are connected together.