fwbrasil / activate

Abandoned: Pluggable persistence in Scala
GNU Lesser General Public License v2.1
299 stars 46 forks source link

when sort by class nested property the result is incorrect #74

Open lshoo opened 11 years ago

lshoo commented 11 years ago

In the activate-example-play, the Company is the Computer nested property. I run the example, that is fine except this issue: In the http://localhost:9000/computers page, or sort by name, introduced, discontiued, e.g. http://localhost:9000/computers?s=-3&f=ab, that is ok. activate_issue2 activate_issue3

but when sort by company http://localhost:9000/computers?s=5&f=ab, the problem happen: activate_issue1 This is an issue?

lshoo commented 11 years ago

This is the Company object define: object Computer {

def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1, filter: String = "*"): Page[(Computer, Option[Company])] = transactional {
    val pagination =
        paginatedQuery {
            (c: Computer) =>
                where(toUpperCase(c.name) like filter.toUpperCase) select (c) orderBy {
                    orderBy match {
                        case -2 =>
                            c.name desc
                        case -3 =>
                            c.introduced desc
                        case -4 =>
                            c.discontinued desc
                        case -5 =>
                            c.company.map(_.name) desc
                        case 2 =>
                            c.name
                        case 3 =>
                            c.introduced
                        case 4 =>
                            c.discontinued
                        case 5 =>
                            c.company.map(_.name)
                    }
                }
        }

    val navigator = pagination.navigator(pageSize)
    if (navigator.numberOfResults > 0) {
        val p = navigator.page(page)
        Page(p.map(c => (c, c.company)), page, page * pageSize, navigator.numberOfResults)
    } else
        Page(Nil, 0, 0, 0)
}

}

full code is here: https://github.com/fwbrasil/activate-example-play/blob/master/app/models/Models.scala

fwbrasil commented 11 years ago

Hi lshoo.

Thanks for the detailed report. This is a bug due the absence of an outer join on the company that is optional. I will provide a fix in the next weeks.

Regards,

Flavio

lshoo commented 11 years ago

Thanks Flavio