This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for GRAILS-8757 "In unit tests, back reference is not set for one…
…-to-one association"
- Loading branch information
1 parent
ba4af68
commit de730c6
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...store-gorm-test/src/test/groovy/org/grails/datastore/gorm/HasOneSetInverseSideSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.grails.datastore.gorm | ||
|
||
import grails.persistence.Entity | ||
import spock.lang.Issue | ||
import grails.gorm.tests.GormDatastoreSpec | ||
|
||
/** | ||
*/ | ||
class HasOneSetInverseSideSpec extends GormDatastoreSpec{ | ||
|
||
@Issue('GRAILS-8757') | ||
void "Test that saving a one-to-one automatically sets the inverse side"() { | ||
when:"A bidirectional one-to-one is saved" | ||
def address = new HouseAddress(street:"Street 001") | ||
def house = new House(name:"Some house", address: address) | ||
|
||
house.save(flush:true) | ||
|
||
then:"The inverse side is autmotically set" | ||
house.id != null | ||
address.house != null | ||
|
||
when:"The association is queried" | ||
session.clear() | ||
house = House.get(house.id) | ||
|
||
then:"The data model is valid" | ||
house.id != null | ||
house.address != null | ||
house.address.house != null | ||
|
||
|
||
} | ||
|
||
@Override | ||
List getDomainClasses() { | ||
[House, HouseAddress] | ||
} | ||
|
||
|
||
} | ||
|
||
@Entity | ||
class House { | ||
Long id | ||
String name | ||
|
||
HouseAddress address | ||
static hasOne = [address: HouseAddress] | ||
} | ||
|
||
@Entity | ||
class HouseAddress { | ||
Long id | ||
String street | ||
|
||
House house | ||
} |