Find() bug with :conditions?

I’m not sure whether this is a bug in find() or just my fault.

class Article < ActiveRecord::Base
belongs_to :journal
has_and_belongs_to_many :authors
has_and_belongs_to_many :users
end

class Author < ActiveRecord::Base
has_and_belongs_to_many :articles
end

class Journal < ActiveRecord::Base
has_many :articles
end

def index
@lastname = session[‘user’].lastname
@article_pages = Paginator.new self, Article.count, 10,
@params[‘page’]
@articles = Article.find :all,
:include => [:journal, :authors],
:conditions => [“authors.last_name=?”,
@lastname],
:order => “pub_date desc”
end

===> NO ERROR

Now, If I add :limit as follows,

def index
@lastname = session[‘user’].lastname
@article_pages = Paginator.new self, Article.count, 10,
@params[‘page’]
@articles = Article.find :all,
:include => [:journal, :authors],
:conditions => [“authors.last_name=?”,
@lastname],
:order => “pub_date desc”,
:limit => @article_pages.items_per_page
end

===>
NoMethodError in Article#index
private method `scan’ called for [“authors.last_name=?”, “Lee”]:Array

Even if @article_pages.items_per_page is replaced with 10, same error.

def index
@lastname = session[‘user’].lastname
@article_pages = Paginator.new self, Article.count, 10,
@params[‘page’]
@articles = Article.find :all,
:include => [:journal, :authors],
:conditions => [“authors.last_name=?”,
@lastname],
:order => “pub_date desc”,
:limit => @article_pages.items_per_page,
:offset => @article_pages.current.offset
end

===>
NoMethodError in Article#index
private method `scan’ called for [“authors.last_name=?”, “Lee”]:Array

If I comment out the :conditions line, the error is gone.

Is this a bug or my fault?

Hi !

2005/11/16, Kyungjoon L. [email protected]:

end
I can’t remember where I’ve seen this, but there’s a limitation using
has_and_belongs_to_many and :limit in find. I tried Googling around,
but found no reference.

Someone else can chime in at this time and give all of us the reference.

Bye !