Guest User

Untitled

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class Place < ActiveRecord::Base
  2. has_many :place_promotions
  3. has_many :livebookings_promos, :through => :place_promotions, :source => :livebookings_promo,
  4. :conditions => "place_promotions.promotion_type = 'LivebookingsPromo'"
  5. has_many :coupons, :through => :place_promotions, :source => :coupon,
  6. :conditions => "place_promotions.promotion_type = 'Coupon'"
  7.  
  8. def promotions
  9. self.livebookings_promos + self.coupons
  10. end
  11. end
  12.  
  13. class PlacePromotion < ActiveRecord::Base
  14. belongs_to :place
  15. belongs_to :promotion, :polymorphic => true
  16.  
  17. belongs_to :livebookings_promo, :class_name => 'LivebookingsPromo', :foreign_key => 'promotion_id'
  18.  
  19. belongs_to :coupon, :class_name => 'Coupon', :foreign_key => 'promotion_id'
  20. end
  21.  
  22. class LivebookingsPromo < ActiveRecord::Base
  23. has_many :place_promotions, :as => :promotion
  24. has_many :places, :through => :place_promotions
  25. end
  26.  
  27. class Coupon < ActiveRecord::Base
  28. has_many :place_promotions, :as => :promotion
  29. has_many :places, :through => :place_promotions
  30. end
Add Comment
Please, Sign In to add comment