Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEAP v11, chapter 5, section 5.3.1 : fetch parameter oddities #41

Open
marcpa00 opened this issue Aug 22, 2013 · 4 comments
Open

MEAP v11, chapter 5, section 5.3.1 : fetch parameter oddities #41

marcpa00 opened this issue Aug 22, 2013 · 4 comments
Labels

Comments

@marcpa00
Copy link
Contributor

When using def users = User.list(sort: 'loginId', order: 'asc', max: 5, fetch: [posts: 'eager']) the result list has 3 items whereas def users = User.list(sort: 'loginId', order: 'asc', max: 5) has 5.

I wonder if this is a bug in grails (version 2.2.3) ?

Here is a spec that should pass but where the tests using the fetch parameter are failing:

package com.grailsinaction

import grails.plugin.spock.IntegrationSpec

/**
 * Integration tests that should pass, but the one specifying fetch parameter to list() fails.
 */
class UserIntegrationCh531Spec extends IntegrationSpec {

    def setup() {
    }

    def cleanup() {
    }

    def "Static User list with sorting order"() {
        given: "User domain static list() method is used with parameters sort and order"
        def users = User.list(sort: 'id', order: 'asc')

        when: "a copy of the list is sorted by id"
        def copy = users.collect().sort { it.id }

        then: "both are equals"
        users == copy
    }

    def "Static User list with sorting order and eager fetch"() {
        given: "User domain static list() method is used with parameters sort, order and fetch"
        def users = User.list(sort: 'id', order: 'asc', fetch: [posts: 'eager'])

        when: "a copy of the list is sorted by id"
        def copy = users.collect().sort { it.id }

        then: "both are equals"
        users == copy
    }

    def "Static User list with max"() {
        given: "User domain static list() method used with a max parameter"
        def max = 4
        def users = User.list(max: max)

        when: "We count the results"
        def count = users.size()

        then: "it equals the max given"
        count == max
    }

    def "Static User list with max and eager fetch"() {
        given: "User domain static list() method used with a max parameter and fetch"
        def max = 5
        def users = User.list(max: max, fetch: [posts: 'eager'])

        when: "We count the results"
        def count = users.size()

        then: "it equals the max given"
        count == max
    }

}
@pledbrook
Copy link
Contributor

I'll look into it.

@marcpa00
Copy link
Contributor Author

Note : I tried both with jdbc/hibernate logging enabled and disabled, but outcome is the same.

@pledbrook
Copy link
Contributor

Odd. I have just tried this and it's working fine with Grails 2.2.3. I simply can't reproduce. I assume you're running against H2? I wonder if the version of the JDK is having an impact too. I've just tried with Java 6.

@JoeCordingley
Copy link

Same problem with grails 3.0.2, although I have a sort and when I remove that it gets the right amount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants