Grails
  1. Grails
  2. GRAILS-8372

Allow reassignment of detached criteria variables

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0-RC2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      If you assign a Where query to an untyped variable like so:

      def authors = Author.where { age > avg(age) }
      

      then the authors variable is given an explicit type of DetachedCriteria by the underlying AST transform. This results in class cast errors if you do things like:

      authors = "Some text"
      

      This is very strange for users since the code is perfectly valid Groovy, it's just the AST transformation is having unintended side-effects.

      See GRAILS-8355 for background and sample app.

        Issue Links

          Activity

          Hide
          Graeme Rocher added a comment -

          It is unlikely we'll able to allow re-assignment, the best we can do is fail with a compilation error if re-assignment is attempted. We need to know that a variable is a DetachedCriteria in case the where method is used on the variable in query chaining

          Show
          Graeme Rocher added a comment - It is unlikely we'll able to allow re-assignment, the best we can do is fail with a compilation error if re-assignment is attempted. We need to know that a variable is a DetachedCriteria in case the where method is used on the variable in query chaining

            People

            • Assignee:
              Unassigned
              Reporter:
              Peter Ledbrook
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Last Reviewed:

                Development