For the record--this works, and I think is railsish enough for you guys to
not make fun of me. ;-)
def self.find_by_name_fragment(frag, proj = nil)
# Got to add in the wildcard where we need it.
frag += '%'
# Look for people whose first or last names begin with the fragment.
cond = "(first_name LIKE :frag OR last_name LIKE :frag)"
unless proj.nil?
# We know what project we're looking for new people on--remove anybody
already assigned to that project.
cond += " AND id not in (select person_id from project_people where id
= :proj)"
end
# AR knows to ignore the proj named parameter if it doesn't appear in
the crition string.
options = {:conditions => [cond, {:frag => frag, :proj => proj}]}
Person.find(:all, options)
end