Skip to content

Instantly share code, notes, and snippets.

@foucist
Last active May 3, 2016 00:38
Show Gist options
  • Select an option

  • Save foucist/64f6e68bc6d948c9ab1e to your computer and use it in GitHub Desktop.

Select an option

Save foucist/64f6e68bc6d948c9ab1e to your computer and use it in GitHub Desktop.
scope :either, ->(a, b){where(where(profile: a, block: b).where(profile: b, block: a).where_values.instance_exec { self[0].and(self[1]).or(self[2].and(self[3]))})}
# or
def self.either(a,b)
pb = Arel::Table.new(:profile_blocks)
pb[:profile_id].eq(a).and(pb[:block_id].eq(b)).or(pb[:profile_id].eq(b).and(pb[:block_id].eq(a)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment