Change Values in Controller A for Domain Class B

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Change Values in Controller A for Domain Class B

numxxx
This post was updated on .
Hi,

im newbie in grails. I use three Domain Class Books, Customers and Rents.

My Question:

It is possible if i create a new rent (the rent create use private key from Domain Class Customers and Books) and before i save the new rent that i change a field value in Domain Class Books?

Example: I create a new rent. A rent use the Data from the Customer and the Book that customer want rent. If the rent is create the value for book count should reduce for this rent book (Example from 15 to 14 books).

If this possible how should i do this. I test with this in Controller Rent

def changeBooks(Long id) {
     def p=Books.get(id)
      p.properties
      Books.executeUpdate("update Books p set p.anzahl=anzahl -1")
     redirect view:'edit'

but i get the message


URI
    /rents/changeBooks
Class
    java.lang.NullPointerException
Message
    null
Caused by
    Cannot get property 'properties' on null object


I use the mem H2 DB
Reply | Threaded
Open this post in threaded view
|

Re: Change Values in Controller A for Domain Class B

aladanh
I loved the way you discuss the topic great work thanks for the share.
hotmail login
Reply | Threaded
Open this post in threaded view
|

Re: Change Values in Controller A for Domain Class B

run3unblockedaz
In reply to this post by numxxx
Wow! This can be one particular of the most useful blogs We’ love ever arrive across on this subject. Actually Excellent. I am also a specialist in this topic, therefore, I can understand your effort.
t rex game