Forum: Ruby on Rails find() bug with :conditions?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
819a63977ff0c2099d3b3b1ab620023e?d=identicon&s=25 Joon Lee (seouri)
on 2005-11-16 21:46
(Received via mailing list)
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?
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 francois.beausoleil (Guest)
on 2005-11-17 15:02
(Received via mailing list)
Hi !

2005/11/16, Kyungjoon Lee <seouri@gmail.com>:
> 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 !
This topic is locked and can not be replied to.