Skip to content

Instantly share code, notes, and snippets.

@coderdan
Created May 30, 2013 01:40
Show Gist options
  • Select an option

  • Save coderdan/5675257 to your computer and use it in GitHub Desktop.

Select an option

Save coderdan/5675257 to your computer and use it in GitHub Desktop.
Readability for complex associations
has_many :performances, :dependent => :destroy
has_many :keyword_vendor_instances,
:class_name => 'Scenario::Keyword::VendorInstance',
:foreign_key => :ad_group_vendor_instance_id
has_many :ad_vendor_instances,
:class_name => 'Scenario::Ad::VendorInstance',
:foreign_key => :ad_group_vendor_instance_id
# And not this:
has_many :join_geo_target_scenario_campaign_vendor_instances, :dependent => :destroy, :class_name => 'Join::GeoTargetScenarioCampaignVendorInstance'
has_many :geo_targets, :through => :join_geo_target_scenario_campaign_vendor_instances, :conditions => { :join_geo_target_scenario_campaign_vendor_instances => {:exclusive => false} }
has_many :exclusive_geo_targets, :through => :join_geo_target_scenario_campaign_vendor_instances, :conditions => { :join_geo_target_scenario_campaign_vendor_instances => {:exclusive => true} }, :source => :geo_target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment