Skip to content

Instantly share code, notes, and snippets.

@nomasprime
Created October 2, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomasprime/8e4aa3bfcbbc7c1ba31d to your computer and use it in GitHub Desktop.
Save nomasprime/8e4aa3bfcbbc7c1ba31d to your computer and use it in GitHub Desktop.
class AdminBound < ActiveRecord::Base
scope :sites, -> {
where(arel_table[:iso].eq('BRA').and(Arel::Nodes::NamedFunction.new('st_contains', [arel_table[:geom], Site.arel_table[:lonlat]]))).project(Site.arel_table[Arel.star])
}
end
@smathy
Copy link

smathy commented Oct 2, 2015

class Site < Ac...
  belongs_to :admin_bound
  scope :bound, -> {
    joins(:admin_bound).
    where( admin_bounds: { iso: 'BRA' }).
    where( Arel::Nodes::NamedFunction.new('st_contains', [AdminBound.arel_table[:geom], arel_table[:lonlat]]))
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment