Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created July 14, 2013 13:31
Show Gist options
  • Select an option

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

Select an option

Save mwlang/5994288 to your computer and use it in GitHub Desktop.
Extract of an Attorney model (basically a Person)
class Attorney < ActiveRecord::Base
# Added :uniq qualifier, not without some strife. First, in the Agile 1.2 dev book,
# they incorrectly called the parameter ":unique". Then, when you get a .count
# on this association (attorney.community_organizations.count), it returns the non-
# unique count. So, instead, to receive an accurate count that respects the :uniq
# parameter, use .size, so attorney.community_organizations.size.
has_many :community_organizations,
:through => :affiliations,
:conditions => %{community_organization_type_id != #{CommunityOrganizationType::PROFESSIONAL_TYPE_ID}},
:order => 'name',
:uniq => true
has_many :professional_organizations,
:through => :affiliations,
:source => :community_organization,
:conditions => %{community_organization_type_id = #{CommunityOrganizationType::PROFESSIONAL_TYPE_ID}},
:order => 'name',
:uniq => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment