linked. If you don't want an association linked you can do something
> Maybe to clarify the domain model, I used Burt Beckwith's GORM idioms to
> remove the collection in the hasMany part of the relationship.
>
> The conventional GORM implementation i guess should look something like
> this:
>
> class Mydomain3 {
> String name
>
> static belongsTo = [
> parent: Mydomain3,
> alias: Mydomain3,
> foo: Mydomain3
> ]
> static hasMany = [
> children: Mydomain3,
> aliases: Mydomain3,
> foos: Mydomain3
> ]
> static mappedBy = [
> children: 'parent',
> aliases: 'alias',
> foos: 'foo'
>
> ]
>
> static constraints = {
> parent(nullable: true)
> alias(nullable: true)
> foo(nullable: true)
> }
> }
>
> The fact that the target of there are multiple relationships confuses GORM
> apparently, so that when you assign parent in objetc one, GORM assignes
> alias in object two.
>
>
>
>
> On Thu, Apr 26, 2012 at 9:02 AM, Luis Muniz <
[hidden email]> wrote:
>>
>> bump.
>>
>> Revised example:
>>
>> class Mydomain {
>>
>> String name
>> Mydomain alias
>> Mydomain
>> parent
>>
>> Mydomain foo
>>
>> static constraints = {
>>
>>
>> parent(nullable: true)
>> alias(nullable: true)
>>
>>
>> foo(nullable: true)
>> }
>>
>> }
>>
>> Mydomain.list()*.delete()
>>
>> def one=new Mydomain(name:'one').save()
>>
>>
>> new Mydomain(name:'two', parent:one).save()
>>
>>
>>
>> Mydomain.list().each{
>> println it.
>> name
>>
>> println "parent:${it.parent?.name}"
>> println "alias:${it.alias?.name}"
>> println "foo:${it.foo?.name}"
>>
>>
>> println "============================"
>> }
>>
>>
>> Resulting in:
>>
>> one
>>
>> parent:null
>> alias:two
>> foo:null
>>
>> ============================
>> two
>> parent:one
>> alias:null
>>
>> foo:null
>> ============================
>>
>>
>>
>> On Wed, Apr 25, 2012 at 12:18 PM, Luis Muniz <
[hidden email]> wrote:
>>>
>>> update, in grails 2.0.1 I have the same behaviour.
>>>
>>>
>>> On Wed, Apr 25, 2012 at 9:38 AM, Luis Muniz <
[hidden email]> wrote:
>>>>
>>>> Sorry for crossposting (with stack exchange), but I feel this one is
>>>> justified, as it is a possible bug inside gorm, and in my opinion a
>>>> dangerous one.
>>>>
>>>> Feel free to educate me otherwise:
>>>>
>>>> I have come accross something that at first view seems to be a bug in
>>>> Gorm (grails 1.3.7). I thought I'd post the problem here before going for
>>>> the jira issue, in case I'm getting it wrong.
>>>>
>>>> Here's the issue:
>>>>
>>>> I have one domain class, it refers to a parent object of the same class,
>>>> and also can have a pointer to an alias, also of the same domain class.
>>>>
>>>> This is the domain class:
>>>>
>>>> class Mydomain {
>>>> String name
>>>>
>>>> Mydomain alias
>>>> Mydomain parent
>>>>
>>>> static constraints = {
>>>>
>>>>
>>>>
>>>>
>>>> parent(nullable: true)
>>>> alias(nullable: true)
>>>>
>>>>
>>>>
>>>>
>>>> foo(nullable: true)
>>>> }
>>>>
>>>> }
>>>>
>>>> If I execute the following script:
>>>>
>>>> Mydomain.list()*.delete()
>>>>
>>>> def one=new Mydomain(name:'one').save()
>>>>
>>>>
>>>>
>>>>
>>>> new Mydomain(name:'two', parent:one).save()
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Mydomain.list().each{
>>>> println it.name
>>>>
>>>> println it.alias?.name
>>>> println "============================"
>>>>
>>>> }
>>>>
>>>> I get the following result:
>>>>
>>>> one
>>>> two
>>>> ============================
>>>> two
>>>> null
>>>> ============================
>>>>
>>>> This means that when I set two.parent=one, gorm goes and sets
>>>> one.alias=two.
>>>>
>>>> I guess that gorm does this because it infers that there is a
>>>> bidirectional relationship between one and two, and then sets the first
>>>> property of class Mydomain of object one to the reference of two.
>>>>
>>>> I can see this sort of behaviour working with bidirectional
>>>> relationships between Author and Book (assuming that an author only writes
>>>> one book of course), but in my case this is dangerous, becaus gorm goes and
>>>> overwrites a relationship that has nothing to do with this.
>>>>
>>>> So my question would be, how do I tell GORM to treat this as
>>>> unidirectional nullable relationships?
>>>>
>>>> Thanks for any ideas
>>>>
>>>>
>>>
>>
>