<?xml version="1.0" encoding="UTF-8"?>
<tickets type="array">
  <ticket>
    <assigned-user-id type="integer">51</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">false</closed>
    <created-at type="datetime">2009-02-23T11:10:22-08:00</created-at>
    <creator-id type="integer">25969</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">250</number>
    <permalink>will_paginate-mangles-object-ids-if-named_scope-includes-a-join</permalink>
    <priority type="integer">101</priority>
    <project-id type="integer">466</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>new</state>
    <tag>will_paginate</tag>
    <title>Will_paginate mangles object ids if named_scope includes a :join</title>
    <updated-at type="datetime">2009-02-23T11:16:23-08:00</updated-at>
    <user-id type="integer">25969</user-id>
    <user-name>Adam Florin</user-name>
    <creator-name>Adam Florin</creator-name>
    <assigned-user-name>Chris Wanstrath</assigned-user-name>
    <url>http://err.lighthouseapp.com/projects/466/tickets/250</url>
    <original-body>It looks like if you use will_paginate in conjunction with an ActiveRecord named_scope with a :join, will_paginate will jam the ids of the joined table in place of the actual ids of the returned objects. Kinda hard to explain; it's a weird bug.

I'll pull an example from our source. Take two models, Review and Story, where Review belongs_to :story. If I set up a simple named scope like:

@@@
class Review &lt; ActiveRecord::Base
  named_scope :visible, :conditions =&gt; {:status =&gt; 'visible'}
end
@@@

and then do:

@@@
Review.visible.paginate(:page =&gt; 1)
@@@

All the returned reviews are OK.

However, if I just add a join to that named_scope (perfectly legal) like:

@@@
class Review &lt; ActiveRecord::Base
  named_scope :visible, :conditions =&gt; {'reviews.status' =&gt; ['list', 'feature']},
    :joins =&gt; &quot;JOIN stories ON reviews.story_id=stories.id&quot;
end
@@@

...and then run the same paginate call as above, my results look like:

@@@
[#&lt;Review id: 182, story_id: 182&gt;, #&lt;Review id: 183, story_id: 183&gt;, ...]
@@@

Where the story_ids are all correct and the Review ids are all incorrectly set to match the story ids.

This has to do with how will_paginate or something is parsing the SQL results (which are correct). Note that if I feed an explicit :select to paginate like :select =&gt; &quot;reviews.id, reviews.story_id&quot;, then the ids _are_ correct.</original-body>
    <latest-body>It looks like if you use will_paginate in conjunction with an ActiveRecord named_scope with a :join, will_paginate will jam the ids of the joined table in place of the actual ids of the returned objects. Kinda hard to explain; it's a weird bug.

I'll pull an example from our source. Take two models, Review and Story, where Review belongs_to :story. If I set up a simple named scope like:

@@@
class Review &lt; ActiveRecord::Base
  named_scope :visible, :conditions =&gt; {:status =&gt; 'visible'}
end
@@@

and then do:

@@@
Review.visible.paginate(:page =&gt; 1)
@@@

All the returned reviews are OK.

However, if I just add a join to that named_scope (perfectly legal) like:

@@@
class Review &lt; ActiveRecord::Base
  named_scope :visible, :conditions =&gt; {'reviews.status' =&gt; ['list', 'feature']},
    :joins =&gt; &quot;JOIN stories ON reviews.story_id=stories.id&quot;
end
@@@

...and then run the same paginate call as above, my results look like:

@@@
[#&lt;Review id: 182, story_id: 182&gt;, #&lt;Review id: 183, story_id: 183&gt;, ...]
@@@

Where the story_ids are all correct and the Review ids are all incorrectly set to match the story ids.

This has to do with how will_paginate or something is parsing the SQL results (which are correct). Note that if I feed an explicit :select to paginate like :select =&gt; &quot;reviews.id, reviews.story_id&quot;, then the ids _are_ correct.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;It looks like if you use will_paginate in conjunction with an
ActiveRecord named_scope with a :join, will_paginate will jam the
ids of the joined table in place of the actual ids of the returned
objects. Kinda hard to explain; it's a weird bug.&lt;/p&gt;
&lt;p&gt;I'll pull an example from our source. Take two models, Review
and Story, where Review belongs_to :story. If I set up a simple
named scope like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class Review &amp;lt; ActiveRecord::Base
  named_scope :visible, :conditions =&amp;gt; {:status =&amp;gt; 'visible'}
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then do:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
Review.visible.paginate(:page =&amp;gt; 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All the returned reviews are OK.&lt;/p&gt;
&lt;p&gt;However, if I just add a join to that named_scope (perfectly
legal) like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class Review &amp;lt; ActiveRecord::Base
  named_scope :visible, :conditions =&amp;gt; {'reviews.status' =&amp;gt; ['list', 'feature']},
    :joins =&amp;gt; &amp;quot;JOIN stories ON reviews.story_id=stories.id&amp;quot;
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;...and then run the same paginate call as above, my results look
like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
[#&amp;lt;Review id: 182, story_id: 182&amp;gt;, #&amp;lt;Review id: 183, story_id: 183&amp;gt;, ...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where the story_ids are all correct and the Review ids are all
incorrectly set to match the story ids.&lt;/p&gt;
&lt;p&gt;This has to do with how will_paginate or something is parsing
the SQL results (which are correct). Note that if I feed an
explicit :select to paginate like :select =&amp;gt; &quot;reviews.id,
reviews.story_id&quot;, then the ids &lt;em&gt;are&lt;/em&gt; correct.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">192</assigned-user-id>
    <attachments-count type="integer">3</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2008-10-10T18:12:41-07:00</created-at>
    <creator-id type="integer">15346</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">247</number>
    <permalink>use-namedscope-plugin</permalink>
    <priority type="integer">99</priority>
    <project-id type="integer">466</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>named_scope will_paginate</tag>
    <title>Use NamedScope Plugin</title>
    <updated-at type="datetime">2008-10-26T17:42:25-07:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Ken Collins</creator-name>
    <assigned-user-name>Mislav</assigned-user-name>
    <url>http://err.lighthouseapp.com/projects/466/tickets/247</url>
    <original-body>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/named_scope/tree/master

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.</original-body>
    <latest-body>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/named_scope/tree/master

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.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I created a well tested plugin on my Github account here:
&lt;a href=&quot;http://github.com/metaskills/named_scope/tree/master&quot;&gt;http://github.com/metaskills/nam...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;BTW, all tests are passing in all versions and DBs via rake
test_all.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">192</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2008-06-25T07:17:15-07:00</created-at>
    <creator-id type="integer">24430</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">232</number>
    <permalink>systemstackerror-stack-level-too-deep</permalink>
    <priority type="integer">95</priority>
    <project-id type="integer">466</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag>will_paginate</tag>
    <title>SystemStackError: stack level too deep</title>
    <updated-at type="datetime">2008-10-26T02:32:11-07:00</updated-at>
    <user-id type="integer">192</user-id>
    <user-name>Mislav</user-name>
    <creator-name>Jeannette</creator-name>
    <assigned-user-name>Mislav</assigned-user-name>
    <url>http://err.lighthouseapp.com/projects/466/tickets/232</url>
    <original-body>Hi all,

I got this error on script/console is there any fix ? Below are print stack:



&gt;&gt; @p = Person.find(106)
=&gt; #&lt;Person id: 106, createdate: &quot;2001-01-17 19:34:19&quot;, firstname: &quot;Peter&quot;&gt;
&gt;&gt; @p.paper
=&gt; [#&lt;Paper id: 1246, title: &quot;I&quot;, summary: nil&gt;, #&lt;Paper id: 968, title: &quot;W&quot;, summary: nil&gt;, #&lt;Paper ident: 923, title: &quot;S&quot;,summary: nil&gt;, #&lt;Paper id: 1200, &gt;.....]
&gt;&gt; @p.paper.size
=&gt; 94
&gt;&gt; @p.paper.class

SystemStackError: stack level too deep
	from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:138:in `method_missing_without_paginate'
	from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:139:in `method_missing'
	from (irb):3


my models associations:

Person 
has_many :author
has_many :paper :through =&gt; :author


my environment: 

ruby -v ==&gt; ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.2]


rails -v ==&gt; Rails 2.1.0

gem -v ==&gt; 1.0.1

just Successfully installed mislav-will_paginate-2.3.2


Many thanks,

Jeannette</original-body>
    <latest-body>Hi all,

I got this error on script/console is there any fix ? Below are print stack:



&gt;&gt; @p = Person.find(106)
=&gt; #&lt;Person id: 106, createdate: &quot;2001-01-17 19:34:19&quot;, firstname: &quot;Peter&quot;&gt;
&gt;&gt; @p.paper
=&gt; [#&lt;Paper id: 1246, title: &quot;I&quot;, summary: nil&gt;, #&lt;Paper id: 968, title: &quot;W&quot;, summary: nil&gt;, #&lt;Paper ident: 923, title: &quot;S&quot;,summary: nil&gt;, #&lt;Paper id: 1200, &gt;.....]
&gt;&gt; @p.paper.size
=&gt; 94
&gt;&gt; @p.paper.class

SystemStackError: stack level too deep
	from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:138:in `method_missing_without_paginate'
	from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:139:in `method_missing'
	from (irb):3


my models associations:

Person 
has_many :author
has_many :paper :through =&gt; :author


my environment: 

ruby -v ==&gt; ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.2]


rails -v ==&gt; Rails 2.1.0

gem -v ==&gt; 1.0.1

just Successfully installed mislav-will_paginate-2.3.2


Many thanks,

Jeannette</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;
Hi all,
&lt;/p&gt;&lt;p&gt;
I got this error on script/console is there any fix ? Below are print stack:
&lt;/p&gt;&lt;p&gt;
&gt;&gt; @p = Person.find(106)
&lt;/p&gt;&lt;p&gt;
=&gt; #
&lt;/p&gt;&lt;p&gt;
&gt;&gt; @p.paper
&lt;/p&gt;&lt;p&gt;
=&gt; [#, #, #, #.....]
&lt;/p&gt;&lt;p&gt;
&gt;&gt; @p.paper.size
&lt;/p&gt;&lt;p&gt;
=&gt; 94
&lt;/p&gt;&lt;p&gt;
&gt;&gt; @p.paper.class
&lt;/p&gt;&lt;p&gt;
SystemStackError: stack level too deep
&lt;/p&gt;&lt;p&gt;
from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:138:in `method_missing_without_paginate'
&lt;/p&gt;&lt;p&gt;
from /Users/jc/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:139:in `method_missing'
&lt;/p&gt;&lt;p&gt;
from (irb):3
&lt;/p&gt;&lt;p&gt;
my models associations:
&lt;/p&gt;&lt;p&gt;
Person
&lt;/p&gt;&lt;p&gt;
has_many :author
&lt;/p&gt;&lt;p&gt;
has_many :paper :through =&gt; :author
&lt;/p&gt;&lt;p&gt;
my environment:
&lt;/p&gt;&lt;p&gt;
ruby -v ==&gt; ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.2]
&lt;/p&gt;&lt;p&gt;
rails -v ==&gt; Rails 2.1.0
&lt;/p&gt;&lt;p&gt;
gem -v ==&gt; 1.0.1
&lt;/p&gt;&lt;p&gt;
just Successfully installed mislav-will_paginate-2.3.2
&lt;/p&gt;&lt;p&gt;
Many thanks,
&lt;/p&gt;&lt;p&gt;
Jeannette
&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
</tickets>
