Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails validation dependent on related domains
    primarykey
    data
    text
    <p>I have several domain classes that are related and I am trying to figure out how to implement a constraint that depends on multiple domains. The jist of the problem is:</p> <p>Asset has many Capacity pool objects</p> <p>Asset has many Resource objects</p> <p>When I create/edit a resource, need to check that total resources for an Asset doesn't exceed Capacity. </p> <p>I created a service method that accomplishes this, but shouldn't this be done via a validator in the Resource domain? My service class as listed below:</p> <pre><code> def checkCapacityAllocation(Asset asset, VirtualResource newItem) { // Get total Resources allocated from "asset" def allAllocated = Resource.createCriteria().list() { like("asset", asset) } def allocArray = allAllocated.toArray() def allocTotal=0.0 for (def i=0; i&lt;allocArray.length; i++) { allocTotal = allocTotal.plus(allocArray[i].resourceAllocated) } // Get total capacities for "asset" def allCapacities = AssetCapacity.createCriteria().list() { like("asset", asset) } def capacityArray = allCapacities.toArray() def capacityTotal = 0.0 for (def i=0; i&lt;capacityArray.length; i++) { capacityTotal += capacityArray[i].actualAvailableCapacity } if (allocTotal &gt; capacityTotal) { return false } } return true } </code></pre> <p>The problem I am having is using this method for validation. I am using the JqGrid plugin (with inline editing) and error reporting is problematic. If I could do this type of validation in the domain it would make things a lot easier. Any suggestions?</p> <p>Thanks so much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload