This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
652daa0
commit 0e6193f
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...t/groovy/org/grails/datastore/gorm/mongo/InheritanceWithSingleEndedAssociationSpec.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,74 @@ | ||
package org.grails.datastore.gorm.mongo | ||
|
||
import grails.gorm.tests.GormDatastoreSpec | ||
import grails.persistence.Entity | ||
import org.bson.types.ObjectId | ||
import org.grails.datastore.mapping.proxy.EntityProxy | ||
import spock.lang.Issue | ||
|
||
/** | ||
* @author Graeme Rocher | ||
*/ | ||
class InheritanceWithSingleEndedAssociationSpec extends GormDatastoreSpec { | ||
|
||
@Issue('GPMONGODB-304') | ||
void "Test that inheritance works correctly with single ended associations"() { | ||
given:"An association that uses a parent class type" | ||
|
||
def a = new NodeA(a: 'A') | ||
def b = new NodeB(b: 'B', childNode: a) | ||
a.save() | ||
b.save(flush:true) | ||
session.clear() | ||
|
||
when:"The association is queried with the get method" | ||
def nodeB = NodeB.get(b.id) | ||
|
||
|
||
then:"The correct type is returned for the association" | ||
nodeB.childNode instanceof EntityProxy | ||
nodeB.childNode.target instanceof NodeA | ||
|
||
when:"The association is queried with a finder" | ||
nodeB = NodeB.findById(b.id) | ||
then:"The correct type is returned for the association" | ||
nodeB.childNode.target instanceof NodeA | ||
|
||
// nodeB = NodeB.findByB('B') | ||
// assertTrue(nodeB.childNode instanceof NodeA) // doesn't work, childNode is a Node | ||
|
||
|
||
} | ||
|
||
@Override | ||
List getDomainClasses() { | ||
[Node, NodeA, NodeB] | ||
} | ||
} | ||
|
||
@Entity | ||
class Node { | ||
|
||
ObjectId id | ||
|
||
String name | ||
|
||
static constraints = { | ||
} | ||
|
||
static mapping = { | ||
version false | ||
// collection "node" | ||
} | ||
} | ||
|
||
@Entity | ||
class NodeA extends Node { | ||
String a | ||
} | ||
|
||
@Entity | ||
class NodeB extends Node { | ||
String b | ||
Node childNode | ||
} |