Hi,
I'm doing a search, where I have contacts, and also groups for those
contacts.  The association is like this:

contacts:
  has_many :groupers, :dependent => :destroy
  has_many :groups, :through => :groupers

groups:
  has_many :groupers
  has_many :contacts, :through => :groupers

grouper:
  belongs_to :group
  belongs_to :contact

My pagination code looks like this currently:
      if !selected_group_id
        @contacts = @current_user.contacts.paginate(:all, :page =>
params[:page], :conditions => ['name LIKE ?', search_term], :order =>
order_text)
      else
        @contacts = @current_user.contacts.paginate(:all, :page =>
params[:page],
                :join => :groupers,
                :conditions => ["groupers.contact_id = contact.id AND
groupers.group_id = #{selected_group_id} AND name LIKE ?", search_term],
                :order => order_text)
      end

This doesn't do what I hoped, which is find everything where name is
like, and there is a grouper with this same contact id and same group
id.  Clearly I'm an sql newbie and don't know what I'm doing here.  Any
help appreciated.

thanks,
jp
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to