Created
July 16, 2013 19:59
-
-
Save mwlang/6012120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ArgumentError: Invalid mix of scope block and deprecated finder options on ActiveRecord association: Practice.has_many :attorneys_only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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