#247 ✓resolved
Ken Collins

Use NamedScope Plugin

Reported by Ken Collins | October 10th, 2008 @ 06:12 PM

While using WillPaginate along with it's NamedScope patch to help me prepare a rather large app migration from rails 1.2.6 to the latest 2.1.1, I found many problems with the back port of NamedScope.

I created a well tested plugin on my Github account here: http://github.com/metaskills/nam...

This backport plugin is very detailed and even includes a few extra backports like (first|last|all) on ActiveRecord::Base. It even includes patches for attribute conditions where you can pass in association collection and/or named scopes as conditions to other queries in turn generating the correct IN (?) sql syntax.

The plugin is very well tested too, in fact it includes all of the rails 2.1.1 tests for NamedScope that have been rewritten in shoulda/factory_girl. I have implemented this plugin into will_paginate/named_scope and accounted for one test that I think will never work in rails 1.2.6. Thoughts?

BTW, all tests are passing in all versions and DBs via rake test_all.

Comments and changes to this ticket

  • Ken Collins

    Ken Collins October 10th, 2008 @ 07:34 PM

    • Tag set to named_scope, will_paginate

    Another patch, this one I had accidently left out the first method in AssociationCollection.

  • Ken Collins

    Ken Collins October 18th, 2008 @ 10:26 AM

    OK... here is a way better patch that has all the existing tests running (all DBs, all rails versions). Some things I learned in this one.

    1) If you monkey patch and allow named scope, you REALLY need to do that before enabling WillPaginate. I had one test failing in the patch above in 1.2.6 for paginate_recent association test till I realized that WillPaginates method missing needed to come AFTER named_scope's patches.

    2) I think this recent patch is very strong and it uses the latest v0.3 of the named_scope plugin from http://github.com/metaskills/nam...

    Just to enforce... I found this plugin critical when moving from rails 1.2.6 to 2.1 along with the help of WillPaginate, so I think this plugin inside WillPaginate will create a lot of joy for those looking to use it to kill rails classic pagination. Like I did :)

    • Cheers, Ken
  • Ken Collins

    Ken Collins October 26th, 2008 @ 12:17 PM

    Hey Chris!

    Pulling named_scope out of WillPaginate and using the plugin is a GREAT IDEA. First, this is exactly what I did when I was tracking our 1.2.6 towards rails 1.2.6. I used WillPaginate named scope when I started that work and got tons of edge case errors, this why I started the named_scope plugin. It is very well tested!

    Second, using the named_scope plugin along with will_paginate will also ensure that the best hack order is done too. I had an issue when I was doing this patch because there are edge case issue with an embeded WillPaginate with NamedScope becuase the NS patches have to happen before the WP ones.

    So again... I'm in agreement. This ticket can be closed and you can just remove NS from WP. By the way, I also have a project in my github account for using autotest when developing rails plugins. Cheers!

    http://github.com/metaskills/aut...

    • Ken
  • Mislav

    Mislav October 26th, 2008 @ 01:47 PM

    • Assigned user changed from “Chris Wanstrath” to “Mislav”
    • State changed from “new” to “resolved”

    Then we have an agreement. Except, you weren't talking to Chris. It was me all this time :)

    Next version of will_paginate will throw out named_scope backport.

  • Ken Collins

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket

Pages