Skip to content

Instantly share code, notes, and snippets.

@johanb
Created May 10, 2011 12:23
Show Gist options
  • Save johanb/964379 to your computer and use it in GitHub Desktop.
Save johanb/964379 to your computer and use it in GitHub Desktop.
class Spot < ActiveRecord::Base
belongs_to :badge_type
has_and_belongs_to_many :badge_types
end
class BadgeType < ActiveRecord::Base
#has_many :spots
has_and_belongs_to_many :spots
end
#solution
class Spot < ActiveRecord::Base
belongs_to :attainable_badge, :class_name => "BadgeType", :foreign_key => "badge_type_id"
has_and_belongs_to_many :redeemable_badges, :class_name => "BadgeType", :join_table => "badge_types_spots", :association_foreign_key => "badge_type_id"
end
class BadgeType < ActiveRecord::Base
has_and_belongs_to_many :redeem_spots, :class_name => "Spot", :join_table => "badge_types_spots", :association_foreign_key => "spot_id"
has_many :attain_spots, :class_name => "Spot"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment