Skip to content

Instantly share code, notes, and snippets.

@mattraykowski
Last active August 29, 2015 14:06
Show Gist options
  • Save mattraykowski/b85252800e3efaf8d747 to your computer and use it in GitHub Desktop.
Save mattraykowski/b85252800e3efaf8d747 to your computer and use it in GitHub Desktop.
arel-ish ishy Search.name!
def name!
return unless name
person = Person.arel_table
family = Family.arel_table
concat = Arel::Nodes::NamedFunction.new 'concat', [person[:first_name], ' ', person[:last_name]]
where(concat.matches(like(name)).or(
family[:name].matches(like(name)).or(
person[:first_name].matches(like(name.split.first, :after)).and(
person[:last_name].matches(like(name.split.last, :after))))))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment