Permalink
Browse files

createAlias done. first shoot

  • Loading branch information...
fabiooshiro committed Aug 31, 2013
1 parent 1e4129c commit fe72aeb5d616e883319df57a6fd9fd51f6f41d46
@@ -619,5 +619,27 @@ class CriteriaDocTests {
}
}
+ // next release 1.2
+ void test_createAlias(){
+ def paris = new City(name: 'Paris').save()
+ def monet = new Artist(name: 'Monet', city: paris).save()
+ new Portrait(artist: monet, name: 'Soleil levant 1').save()
+
+ def rio = new City(name: 'Rio de Janeiro').save()
+ def portinari = new Artist(name: 'Portinari', city: rio).save()
+ new Portrait(artist: portinari, name: 'Retirantes').save()
+ new Portrait(artist: portinari, name: 'Paisagem de Brodowski').save()
+
+ def diCavalcanti = new Artist(name: 'Di Cavalcanti', city: rio).save()
+ new Portrait(artist: diCavalcanti, name: 'Autorretrato Com Mulata').save()
+
+ def rs = Portrait.withCriteria{
+ createAlias('artist', 'genius')
+ eq('genius.city', rio)
+ order('name', 'asc')
+ }
+ assert 3 == rs.size()
+ assert ['Autorretrato Com Mulata', 'Paisagem de Brodowski', 'Retirantes'] == rs.name
+ }
}
@@ -15,6 +15,7 @@ class PlasticCriteria {
def _instanceValue
def _criteriaValue
def _critOptions
+ def _propertyAlias = [:]
def uniqueResult
@@ -284,7 +285,19 @@ class PlasticCriteria {
def __getProperty(obj, propertyName){
def res = obj
- propertyName.split('\\.').each{ res = it == 'class' ? res.class.name : res."$it" }
+ def currentPath = []
+ propertyName.split('\\.').each{
+ currentPath << it
+ if(it == 'class'){
+ res = res.class.name
+ }else{
+ try{
+ res = res."$it"
+ }catch(MissingPropertyException e){
+ res = res."${_propertyAlias[currentPath.join('.')]}"
+ }
+ }
+ }
return res
}
@@ -333,12 +346,11 @@ class PlasticCriteria {
// nope https://github.com/fabiooshiro/plastic-criteria/issues/2
}
- //should be implemented
def createAlias(property, propertyAlias){
-
+ _propertyAlias.put(propertyAlias, property)
}
- //should be implemented
- def cache(enableCache){
+ def cache(enableCache){
+ // nope
}
}

0 comments on commit fe72aeb

Please sign in to comment.