Announcement Announcement Module
Collapse
No announcement yet.
Problem with selection in view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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

    Comment


    • #3
      Thanks!

      I'll sign up for the User mailing list ;-)

      Comment

      Working...
      X