Grails
  1. Grails
  2. GRAILS-8757

In unit tests, back reference is not set for one-to-one association

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final, 2.0.1, 2.1-RC1
    • Fix Version/s: 2.0.1
    • Component/s: Persistence, Testing
    • Labels:
      None
    • Environment:
      Windows 7, oracle jdk 1.6.0_30
    • Testcase included:
      yes

      Description

      With domain classes House and Address,

      package myapp
      
      class House {
        String name
      
        static hasOne = [address: Address]
      
        static constraints = {
        }
      }
      
      package myapp
      
      class Address {
        String street
      
        House house
      
        static constraints = {
        }
      }
      

      following unit test fails on second assertion:

      package myapp
      
      import grails.test.mixin.TestMixin
      import grails.test.mixin.domain.DomainClassUnitTestMixin
      import org.junit.Test
      
      @TestMixin(DomainClassUnitTestMixin)
      class HouseUnitTests {
        @Test
        public void testBackReferenceUnit() {
          mockDomain(Address)
          mockDomain(House)
      
          def address = new Address(street:"Street 001")
          def house = new House(name:"Some house", address: address)
      
          house.save(flush:true)
      
          assert house.id != null
          assert address.house != null
        }
      }
      

      Same test passes if written like integration test, as illustrated in attached app.

      I'm experiencing this with grails 2.0.0, and 2.0.1 (build 1730) and 2.1.0 (build 253) snapshots.

        Activity

        Show
        Graeme Rocher added a comment - Fixed by https://github.com/SpringSource/grails-data-mapping/commit/de730c69f74d9df3b9ffdf014afc95d31b41ca59

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Damir Murat
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development