grails-data-mapping: added forceUnidirectional

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

grails-data-mapping: added forceUnidirectional

Stefan Armbruster
Hi,

FYI, I've just added a new configuration option for domainclasses in
grails-data-mapping, see http://bit.ly/niOrLT . This is useful for e.g.
a domain classes like

class User {
   
   String name
   User bestBuddy
   static hasMany = [ friends:User, foes: User]
   static forceUnidirectional = [ 'friends', 'foes', 'bestBuddy']

}

Without the 'forceUnidirectional', bestBuddy would become a
bidirectional relation, this is not want is desired. forceUnidirectional
prevents the magic autodetection that is normally done.

This change is not intended to break any existing code.

Any comments on this?

Regards,
Stefan




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grails-data-mapping: added forceUnidirectional

Nick Vaidyanathan
Really? Doesn't hasOne or just a regular inclusion of an object as an instance member normally do this?  Is this a special case because of the class referencing itself? A couple more examples might illuminate the value-add better. 

On Fri, Aug 12, 2011 at 1:50 PM, Stefan Armbruster <[hidden email]> wrote:
Hi,

FYI, I've just added a new configuration option for domainclasses in
grails-data-mapping, see http://bit.ly/niOrLT . This is useful for e.g.
a domain classes like

class User {

  String name
  User bestBuddy
  static hasMany = [ friends:User, foes: User]
  static forceUnidirectional = [ 'friends', 'foes', 'bestBuddy']

}

Without the 'forceUnidirectional', bestBuddy would become a
bidirectional relation, this is not want is desired. forceUnidirectional
prevents the magic autodetection that is normally done.

This change is not intended to break any existing code.

Any comments on this?

Regards,
Stefan




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: grails-data-mapping: added forceUnidirectional

Stefan Armbruster
I'm not sure but hasOne IMHO just puts the fk field into the other table
(when speaking of relational databases). AFAIK hasOne does not force the
relation to be unidirectional.
The given example is currently my only use case for this, it might be
true that it is almost an issue only on self referencing domain classes.

Regards,
Stefan
Am Montag, den 15.08.2011, 00:11 -0700 schrieb Nick Vaidyanathan:

> Really? Doesn't hasOne or just a regular inclusion of an object as an
> instance member normally do this?  Is this a special case because of
> the class referencing itself? A couple more examples might illuminate
> the value-add better.
>
> On Fri, Aug 12, 2011 at 1:50 PM, Stefan Armbruster
> <[hidden email]> wrote:
>         Hi,
>        
>         FYI, I've just added a new configuration option for
>         domainclasses in
>         grails-data-mapping, see http://bit.ly/niOrLT . This is useful
>         for e.g.
>         a domain classes like
>        
>         class User {
>        
>           String name
>           User bestBuddy
>           static hasMany = [ friends:User, foes: User]
>           static forceUnidirectional = [ 'friends', 'foes',
>         'bestBuddy']
>        
>         }
>        
>         Without the 'forceUnidirectional', bestBuddy would become a
>         bidirectional relation, this is not want is desired.
>         forceUnidirectional
>         prevents the magic autodetection that is normally done.
>        
>         This change is not intended to break any existing code.
>        
>         Any comments on this?
>        
>         Regards,
>         Stefan
>        
>        
>        
>        
>         ---------------------------------------------------------------------
>         To unsubscribe from this list, please visit:
>        
>            http://xircles.codehaus.org/manage_email
>        
>        
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grails-data-mapping: added forceUnidirectional

Graeme Rocher
Administrator
In reply to this post by Stefan Armbruster
Maybe it should reuse mappedBy instead?

ie

class User {

  String name
  User bestBuddy
  static hasMany = [ friends:User, foes: User]
  static mappedBy = [ 'friends':false, 'foes':false, 'bestBuddy':false]

}

On Fri, Aug 12, 2011 at 10:50 PM, Stefan Armbruster
<[hidden email]> wrote:

> Hi,
>
> FYI, I've just added a new configuration option for domainclasses in
> grails-data-mapping, see http://bit.ly/niOrLT . This is useful for e.g.
> a domain classes like
>
> class User {
>
>   String name
>   User bestBuddy
>   static hasMany = [ friends:User, foes: User]
>   static forceUnidirectional = [ 'friends', 'foes', 'bestBuddy']
>
> }
>
> Without the 'forceUnidirectional', bestBuddy would become a
> bidirectional relation, this is not want is desired. forceUnidirectional
> prevents the magic autodetection that is normally done.
>
> This change is not intended to break any existing code.
>
> Any comments on this?
>
> Regards,
> Stefan
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grails-data-mapping: added forceUnidirectional

pledbrook
In reply to this post by Nick Vaidyanathan
> Really? Doesn't hasOne or just a regular inclusion of an object as an
> instance member normally do this?  Is this a special case because of the
> class referencing itself? A couple more examples might illuminate the
> value-add better.

hasOne with GORM/Hibernate seems to require a bidirectional relationship.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grails-data-mapping: added forceUnidirectional

Stefan Armbruster
In reply to this post by Graeme Rocher
I've changed this in http://bit.ly/oS4tG0 with a slight difference from
Graeme's suggestion:

class User {
   String name
   User bestBuddy
   static hasMany = [ friends:User, foes: User]
   static mappedBy = [ friends:null, foes:null, bestBuddy:null]
}

The difference are the values of the mappedBy map: they need to be
explicitly null for forcing unidirectional assocations. Using 'false'
here causes trouble in some locations since the value gets casted to
String causing exceptions in this case. Using null as value prevents
this.

Regards,
Stefan

>
Am Dienstag, den 16.08.2011, 09:19 +0200 schrieb Graeme Rocher:

> Maybe it should reuse mappedBy instead?
>
> ie
>
> class User {
>
>   String name
>   User bestBuddy
>   static hasMany = [ friends:User, foes: User]
>   static mappedBy = [ 'friends':false, 'foes':false, 'bestBuddy':false]
>
> }
>
> On Fri, Aug 12, 2011 at 10:50 PM, Stefan Armbruster
> <[hidden email]> wrote:
> > Hi,
> >
> > FYI, I've just added a new configuration option for domainclasses in
> > grails-data-mapping, see http://bit.ly/niOrLT . This is useful for e.g.
> > a domain classes like
> >
> > class User {
> >
> >   String name
> >   User bestBuddy
> >   static hasMany = [ friends:User, foes: User]
> >   static forceUnidirectional = [ 'friends', 'foes', 'bestBuddy']
> >
> > }
> >
> > Without the 'forceUnidirectional', bestBuddy would become a
> > bidirectional relation, this is not want is desired. forceUnidirectional
> > prevents the magic autodetection that is normally done.
> >
> > This change is not intended to break any existing code.
> >
> > Any comments on this?
> >
> > Regards,
> > Stefan
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >    http://xircles.codehaus.org/manage_email
> >
> >
> >
>
>
>






---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email