-
Jul 24th, 2012, 03:12 AM
#1
Problem with selection in view
Hi all,
Here is a newbee question,
I want a list of a "domain" in a view like :
<g:each in="${contractItemInstanceList}" status="i" var="contractItemInstance">
But now i want to get a list of all contractItemInstance wit a specific customer.id I tried everything but no succes...
Here are the domain classes:
class ContractItem {
Customer customer
Space space
String contractID
....
class Customer {
String debcode
String name
....
static hasMany = [contactPersons:ContactPerson,contractItems:Contrac tItem]
in mySql it is : SELECT * FROM `contract_item` WHERE `customer_id`=someValue...
Who can help me out?
Thanks
David
-
Jul 24th, 2012, 09:55 AM
#2
Given a customer id, you can find all related ContractItem instances with "def items = ContractItem.findAllByCustomer(Customer.load(custo merId))". In this case I'm using the load() method to avoid an unnecessary database query for the Customer instance. If you've already loaded it for another reason (e.g. with get()) then just use that: ContractItem.findAllByCustomer(customer)
Then add that to the model map that you're returning from the action
[itemsByCustomer: items, ...]
and loop through them like you were before:
<g:each in="${itemsByCustomer}" status="i" var="contractItemInstance">
p.s. You'll be better off asking questions on the User mailing list since there are a lot more users participating there. Sign up at http://grails.org/Mailing+Lists
-
Jul 25th, 2012, 11:11 AM
#3
Thanks!
I'll sign up for the User mailing list ;-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules