build-test-data icon indicating copy to clipboard operation
build-test-data copied to clipboard

Calling get on base class after building subclass instance does not work

Open piotrgajow opened this issue 7 years ago • 1 comments

Having two domain classes, when one extends the other using tablePerHierarchy mechanism produces strange results when building test data.

How to reproduce:

  1. Create base domain class Base
  2. Create domain class Subclass extending Base
  3. Inside test build instance of Subclass def instance = Subclass.build()
  4. Running Base.get(instance.id) results in null whereas it should return instance object

Workaround:

Running Base.list() or Subclass.list() before the get fixes the issue.

GitHub with reproduction:

https://github.com/piotrgajow/Sandbox/tree/grails-BuildTestDataPlugin-InheritanceIssue

All of tests from this specification pass.

Environment:

Plugin: 3.0.1 OS: Windows 10 Gradle: 3.4.1 Grails: 3.2.8 Groovy: 2.4.7 JVM: 1.8.0_131

piotrgajow avatar Jan 03 '18 22:01 piotrgajow

I have also found out, that calling load or findById methods do work.

piotrgajow avatar Jan 04 '18 09:01 piotrgajow