Still no answer…anyone have something better? Okay complex 2 part question here. I have an Android registration page that gathers information customer name, address, email, phone,… When they click submit I want to send that data to a webservice, that is using Groovy, grails and Hibernate, I am creating. So my First question how do I send that data to my webservice, can some give an example?
Once I send that data on the Webservice, how do I make a complex insert into 2 tables from my Groovy scripts, where customer table has id of address table ? These are legacy tables so the standard domains don’t work since id column name is not the standard “id”. and the relationship is one customer row per address_book row.
Customer table has id, name, email, username, password and address_id
Address table has id, address, city state, zip …
here are my domains for addressbook and customers:
class AddressBook {
String entryStreetAddress
String entryStreetAddress2
String entryPostcode
String entryCity
Integer entryState
Integer entryCountryId
static mapping = {
id column: "address_book_id"
version false
}
}
Heres the legacy customers table notice customerDefaultAddressId is the address_book_id in previous domain:
class Customers {
String customersFirstname
String customersMname
String customersLastname
String customersEmailAddress
Integer customersDefaultAddressId //address id joins AddressBook to Customers
String customersTelephone
String customersUsername
String customersPassword
static mapping = {
id column: "customers_id"
version false
}
}
Okay since no one answered this I will answer it my self. What I did was fairly easy once I setup the data properly in the JSON object by naming index name the same as th column name . I was able to add a mixture of customer table objects and address table objects. Once you call up the URI groovy script you can easily save to each table with minimal effort. Here is the JSON object setup in the Android Activity in the OnClick method when hitting save button:
Then on the Groovy side for my webservices all I do to save the Customer info for the table is: