Has_and_belongs_to_many include problem


#1

hey,

i have users who are in groups, and i have a search form, where i can
search on
group, user lastname, and user firstname.
All this is also with pagination.

these are my models
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end

in my controller i do this
THIS works (but in need pagination)
@users2 = User.find_by_sql(“select users.* from groups, users,
groups_users
where groups.id = " + @group_id.to_s + " and groups_users.group_id =
groups.id
and groups_users.user_id = users.id and users.last_name like '%” +
@last_name.to_s + “%’ order by users.last_name ASC, users.first_name
ASC”)

i get an error on this (can anyone help me???)
@user_pages, @users = paginate :user, :conditions => [‘users.firm_id = ?
and
users.first_name like ? and users.last_name like ?’, @firm_id,
“%#{@first_name}%”, “%#{@last_name}%”] ,:include => [:groups], :order_by
=>
“users.last_name ASC, users.first_name ASC”, :per_page => 10

private method `scan’ called for #Array:0x31da378

RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
active_record/associations.rb:964:ininclude_eager_conditions?' :952:inconstruct_finder_sql_for_association_limiting’
active_record/associations.rb:946:inselect_limited_ids_list' active_record/associations.rb:939:inadd_limited_ids_condition!’
:929:inconstruct_finder_sql_with_included_associations' active_record/associations.rb:917:inselect_all_rows’
active_record/associations.rb:830:infind_with_associations' active_record/base.rb:411:infind’
action_controller/pagination.rb:174:infind_collection_for_pagination' action_controller/pagination.rb:192:inpaginator_and_collection_for’
action_controller/pagination.rb:124:in`paginate’

active_record/associations.rb:964:ininclude_eager_conditions?' 952:inconstruct_finder_sql_for_association_limiting’
active_record/associations.rb:946:inselect_limited_ids_list' active_record/associations.rb:939:inadd_limited_ids_condition!’
:929:inconstruct_finder_sql_with_included_associations' active_record/associations.rb:917:inselect_all_rows’
active_record/associations.rb:830:infind_with_associations' active_record/base.rb:411:infind’
action_controller/pagination.rb:174:infind_collection_for_pagination' action_controller/pagination.rb:192:inpaginator_and_collection_for’
action_controller/pagination.rb:124:inpaginate' action_controller/base.rb:841:insend’
action_controller/base.rb:841:inperform_action_without_filters' action_controller/filters.rb:332:inperform_action_without_benchmark’
action_controller/benchmarking.rb:69:inperform_action_without_rescue' action_controller/benchmarking.rb:69:inmeasure’
action_controller/benchmarking.rb:69:inperform_action_without_rescue' action_controller/rescue.rb:82:inperform_action’
action_controller/base.rb:365:in`send’