#51 ✓resolved
Marcel Ruegenberg

Multiple conditions on single attribute?

Reported by Marcel Ruegenberg | February 11th, 2009 @ 07:10 AM

Is it possible to have multiple conditions on a single attribute?

search = User.new_search
search.conditions.name_like = "Foo"
search.conditions.or_name_like = "Bar"

Currently, this only uses one of the two conditions, it generates something like

... WHERE name LIKE "Foo"

instead of joining the two conditions with OR.

My current workaround is to use groups:

search = User.new_search
search.conditions.group do |group|
  group.or_group do |group|
    group.name_like = "Foo"
  group.or_group do |group|
    group.name_like = "Bar"

This works, but is kind of verbose...

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson February 17th, 2009 @ 03:22 AM

    • State changed from “new” to “resolved”

    Yes, you need to pass it an array of values. So:

    search.conditions.name_like = ["Foo", "Bar"]

    Hope this helps.

  • Marcel Ruegenberg

    Marcel Ruegenberg February 27th, 2009 @ 08:08 AM

    The grouping with the array of values works allright, but they are joined by an AND...

    search.conditions.name_like = ["Foo", "Bar"] 

    would result in something like

    ... AND (name LIKE '%FOO%' AND name LIKE '%Bar%')...

    which obviously is never what we want.

  • Marcel Ruegenberg

    Marcel Ruegenberg March 2nd, 2009 @ 04:12 AM

    Adding the line

    self.join_arrays_with_or = true

    to condition/like.rb fixes this for me.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Referenced by