SHARE
TWEET

Untitled

a guest Jun 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Group < ActiveRecord::Base
  2.   has_many :projects
  3.   has_many :personal_blogs
  4. end
  5.  
  6. class Project < ActiveRecord::Base
  7.   has_many :events, :as => :event_producer
  8. end
  9.  
  10. class PersonalBlog < ActiveRecord::Base
  11.   has_many :events, :as => :event_producer
  12. end
  13.  
  14. class Event < ActiveRecord::Base
  15.   belongs_to :event_producer, :polymorphic => true
  16. end
  17.      
  18. class Group < ActiveRecord::Base
  19.   has_many :projects
  20.   has_many :personal_blogs
  21.  
  22.   def events
  23.     Event.find(:all, :conditions => ['(type = ? AND event_producer_id IN (?)) OR (type = ? AND event_producer IN (?))', 'project', project_ids, 'personal_blog', personal_blog_ids])
  24.   end
  25. end
  26.      
  27. class Group < ActiveRecord::Base
  28.   has_many :projects
  29.   has_many :personal_blogs
  30.  
  31.   def all_events
  32.     projects.events + personal_blogs.events
  33.   end
  34. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top