Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class Event < ActiveRecord::Base
  2. has_many :event_ocurrences
  3. has_many :locations, :through => :event_ocurrences
  4. # has_many :regions, :finder_sql => "select * from regions, locations, event_ocurrences, events where regions.id=locations.region_id and locations.id=event_ocurrences.location_id and event_ocurrences.event_id=events.id and events.id='241'"
  5.  
  6.  
  7. def regions
  8. locations.collect {| location | location.region}.uniq
  9. end
  10.  
  11. end
  12.  
  13. class EventOcurrence < ActiveRecord::Base
  14. belongs_to :event
  15. belongs_to :location
  16. end
  17.  
  18. class Location < ActiveRecord::Base
  19. belongs_to :region
  20. has_many :event_ocurrences
  21. has_many :events, :through => :event_ocurrences
  22. end
  23.  
  24. class Region < ActiveRecord::Base
  25. has_many :locations
  26. end
Add Comment
Please, Sign In to add comment