Changeset 227


Ignore:
Timestamp:
Mar 3, 2010, 12:06:00 PM (9 years ago)
Author:
duh
Message:
  • Template::findAllByEntity(..) did not work as expected. Now you are able to select all Templates of a certain entity by -for example- doing: findAllByEntity(dbnp.studycapturing.Subject) which returns an ArrayList? of matching Templates
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/Template.groovy

    r224 r227  
    2424        }
    2525
     26        /**
     27         * overloaded toString method
     28         * @return String
     29         */
    2630        def String toString() {
    2731                return this.name;
     
    3034        /**
    3135         * Look up the type of a certain template subject field
    32          * @param fieldName The name of the template field
    33          * @return The type (static member of TemplateFieldType) of the field, or null of the field does not exist
     36         * @param       String  fieldName The name of the template field
     37         * @return      String  The type (static member of TemplateFieldType) of the field, or null of the field does not exist
    3438         */
    3539        def TemplateFieldType getFieldType(String fieldName) {
     
    4044        }
    4145
     46        /**
     47         * get all field of a particular type
     48         * @param       Class   fieldType
     49         * @return      ArrayList
     50         */
    4251        def getFieldsByType(TemplateFieldType fieldType) {
    4352                def result = fields.findAll {
     
    4655                return result;
    4756        }
     57
     58        /**
     59         * overloading the findAllByEntity method to make it function as expected
     60         * @param       Class           entity (for example: dbnp.studycapturing.Subject)
     61         * @return      ArrayList
     62         */
     63        public static findAllByEntity(java.lang.Class entity) {
     64                def results = []
     65
     66                // this should not work in static context, however it does so I'll keep
     67                // this in for now :)
     68                this.findAll().each() {
     69                        if (entity.equals(it.entity)) {
     70                                results[ results.size() ] = it
     71                        }
     72                }
     73
     74                return results
     75        }
    4876}
Note: See TracChangeset for help on using the changeset viewer.