Method: SQL::Maker::Condition#compose_or

Defined in:
lib/sql/maker/condition.rb

#compose_or(other) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/sql/maker/condition.rb', line 159

def compose_or(other)
  if self.sql.empty?
    if other.sql.empty?
      return new_condition
    end
    return new_condition(
      :sql => ['(' + other.as_sql() + ')'],
      :bind => other.bind,
    )
  end
  if other.sql.empty?
    return new_condition(
      :sql => ['(' + self.as_sql() + ')'],
      :bind => self.bind,
    )
  end

  # return value is enclosed with '()'.
  # because 'OR' operator priority less than 'AND'.
  return new_condition(
    :sql => ['((' + self.as_sql() + ') OR (' + other.as_sql() + '))'],
    :bind => self.bind + other.bind,
  )
end