problems with retrieving data that was saved outside of a grails webflow

Posted by callie16 on Stack Overflow See other posts from Stack Overflow or by callie16
Published on 2010-04-27T09:20:20Z Indexed on 2010/04/27 9:23 UTC
Read the original article Hit count: 256

Filed under:
|
|
|
|

Hi, this is actually connected to an earlier question of mine here.

Anyway, I have 3 domains that look like this:

class A {
  ...
  static hasMany = [ b : B ]
  ...
}

class B {
  ...
  static belongsTo = [ a : A ]
  static hasMany = [ c : C ]
  ...
}

class C {
  ...
  static belongsTo = [ b : B ]
  ...
}

In my GSP page, I call an action in the Controller via a remote function in a javascript block (I'm using Dojo so I'm passing data to be saved this way... it's not a form per se so I use JSON for now to pass the data to the Controller). Let's say, I'm calling something like this:

def someAction = {
   def jsonArr = [parse the JSON here]
   def tmpA = A.get(params.id)
   ...
   def tmpB = new B()
   b.someParam = jsonArr.someParam
   ...
   def tmpC = new C()
   tmpC.cParam = jsonArr.cParam

   tmpB.addToC(tmpC)
   tmpB.save(flush: true) //this may or may not be here but I'm adding it for the sake of completeness

   tmpA.addToB(tmpB)
   tmpA.save(flush: true)

   // NOTE: If I check here via println or whatnot, tmpA has a tmpB which has a tmpC... in other words, the data got saved. It's also in the DB.
   redirect(action: 'order' ...)
}

Then comes the fun part. Here's the webflow sample:

def orderFlow = {
   ...
   someStateIShouldEndUpIn {
      on("next") { // or on previous... doesn't matter
         def anId = params.id
         def currA = A.get(anId) // this does NOT return a null value
         def testB = currA.b // this DOES return a null value
      }.to("somePage")
      ...
   }
   ...
}

Any ideas on why this happens? Moreover, when I dump the data of currA, b=null... instead of b=[] or b=[contents of tmpB].

Any help would be seriously appreciated... been at this for a couple of days now...

Thanks!

© Stack Overflow or respective owner

Related posts about grails

Related posts about groovy