Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Place < ActiveRecord::Base
- has_many :place_promotions
- has_many :livebookings_promos, :through => :place_promotions, :source => :livebookings_promo,
- :conditions => "place_promotions.promotion_type = 'LivebookingsPromo'"
- has_many :coupons, :through => :place_promotions, :source => :coupon,
- :conditions => "place_promotions.promotion_type = 'Coupon'"
- def promotions
- self.livebookings_promos + self.coupons
- end
- end
- class PlacePromotion < ActiveRecord::Base
- belongs_to :place
- belongs_to :promotion, :polymorphic => true
- belongs_to :livebookings_promo, :class_name => 'LivebookingsPromo', :foreign_key => 'promotion_id'
- belongs_to :coupon, :class_name => 'Coupon', :foreign_key => 'promotion_id'
- end
- class LivebookingsPromo < ActiveRecord::Base
- has_many :place_promotions, :as => :promotion
- has_many :places, :through => :place_promotions
- end
- class Coupon < ActiveRecord::Base
- has_many :place_promotions, :as => :promotion
- has_many :places, :through => :place_promotions
- end
Add Comment
Please, Sign In to add comment