Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created July 16, 2013 19:59
Show Gist options
  • Select an option

  • Save mwlang/6012120 to your computer and use it in GitHub Desktop.

Select an option

Save mwlang/6012120 to your computer and use it in GitHub Desktop.
class Practice < ActiveRecord::Base
default_scope order(:name)
has_many :attorneys, -> { where(active: true)}, :through => :attorney_practice_links
has_many :attorneys_only, -> {where(active: true, is_attorney: true) },
:through => :attorney_practice_links,
:include => [:position],
:source => :attorney
has_many :non_attorneys, -> { where(active: true, is_attorney: false).order('positions.name, attorneys.last_name, attorneys.first_name') },
:through => :attorney_practice_links,
:include => [:position],
:source => :attorney
# ...
end
ArgumentError: Invalid mix of scope block and deprecated finder options on ActiveRecord association: Practice.has_many :attorneys_only
class Practice < ActiveRecord::Base
default_scope order(:name)
has_many :attorneys, -> { where(active: true)}, :through => :attorney_practice_links
has_many :attorneys_only, :through => :attorney_practice_links,
:include => [:position],
:source => :attorney,
:conditions => 'attorneys.active = 1 AND positions.is_attorney = 1'
has_many :non_attorneys, :through => :attorney_practice_links,
:include => [:position],
:source => :attorney,
:conditions => 'attorneys.active = 1 AND positions.is_attorney = 0',
:order => 'positions.name, attorneys.last_name, attorneys.first_name'
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment