Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:12:31+00:00 2026-06-08T08:12:31+00:00

I am trying to take advantage of Grails’ ability to handle data binding for

  • 0

I am trying to take advantage of Grails’ ability to handle data binding for a one-to-many association. I am able to successfully assigning to the relationship but removing single elements or all of them is not working.

Here is an example of what my model looks like:

class Location {
    Float latitude
    Float longitude
}

class Route {
    Location start
    Location stop

    static belongsTo: [courier: Courier]
}

class Courier {
    String name
    static hasMany = [pickups: Location]
}

class ScheduledCourier extends Courier {
    static hasMany = [routes: Route]

    static mapping = {
        routes(cascade: 'all-delete-orphan')
    }
}

When creating a new ScheduledCourier object via a website, I can pass a list of Routes to automatically bind with markup like this:

<input type="hidden" name="routes[0].latitude" value="5" />
<input type="hidden" name="routes[0].longitude" value="5" />
<input type="hidden" name="routes[1].latitude" value="10" />
<input type="hidden" name="routes[1].longitude" value="10" />

This works for me just fine in my controller:

class CourierController {
    // Very simplistic save
    def saveScheduled = {
        def courier = new ScheduledCourier(params)
        courier.save()
    }

    // Very simplistic update
    def update = {
        def courier = Courier.get(params.id)
        courier.properties = params
        courier.save()
    }
}

If I use the following markup instead, I can step through the debugger and see that the routes property is now [] and the object saves fine but the records are not removed from the database.

<input type="hidden" name="routes" value="" />

In addition, if I sent markup like this:

<input type="hidden" name="routes[0].latitude" value="5" />
<input type="hidden" name="routes[0].longitude" value="5" />

courier.routes will not be updated to only contain the 1 object.

Has anyone seen this behavior?

This is Grails 1.3.7…at least for now.

Wrote an integration test that reproduces this behavior:

public void testCourierSave() {
    def l1 = new Location(latitude: 5, longitude: 5).save(flush: true)
    def l2 = new Location(latitude: 10, longitude: 10).save(flush: true)

    def params = ["name": "Courier", "pickups[0].id": l1.id, "pickups[1].id": l2.id,
        "routes[0].start.id": l1.id, "routes[0].stop.id": l2.id,
        "routes[1].start.id": l2.id, "routes[1].stop.id": l1.id]

    def c1 = new ScheduledCourier(params).save(flush: true)

    assertEquals(2, c1.routes.size())

    params = [routes: ""]
    c1.properties = params
    c1.save(flush: true)
    c1.refresh()    // Since the Routes aren't deleted, this reloads them

    assertEquals(0, c1.routes.size())    // Fails

    assertEquals([], Route.findAllByCourier(c1))    // Fails if previous assert is removed
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:12:32+00:00Added an answer on June 8, 2026 at 8:12 am

    I wonder if the following is happening:

    When passing the params [routes:""] the framework is ignoring it as it’s just an empty string.

    Similarly <input type="hidden" name="routes[0].latitude" value="5" /> probably just updates the zeroth route entry in the collection, the others aren’t deleted because all you’ve told it is that the latitude value of the zeroth route should be 5, not that this is should now be the only route in the collection.

    To get the effect you want, you’ll need to add a routes.clear() before binding the parameters.

    To control when the state of the model is persisted to the database you can use Spring transactionality which is available in Grails. This would allow you to revert to the original state of the object if subsequent processing failed. eg:

    Courier.withTransaction {status ->
    
      // Load the courier
    
      //clear the existing routes
    
      // bind the new properties
    
      // perform extra processing
    
      //if the object is invalid, roll back the changes
      status.setRollbackOnly()
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to take advantage of hardware encryption of LTO5 devices using ioctl
In some XPages applications I'm trying to take advantage of org.apache.commons.lang package that is
I am using the jquery plugin datatables and am trying to take advantage of
I am trying to create an application to take advantage of OpenSSH to create
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
Im trying to take a link either when clicked or hover over be able
I'm trying to take advantage of Symfony's authentication and authorization capabilities however I'm somewhat
I'm trying to take advantage of Bidirectional serialization of some relational Linq-2-Sql generated entity
I am creating an image processing application in C# and trying to take advantage
I'm using ASP.NET MVC 2.0 and I am trying to take advantage of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.