Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created November 3, 2010 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcocca/661086 to your computer and use it in GitHub Desktop.
Save tcocca/661086 to your computer and use it in GitHub Desktop.
class SearchReport < ActiveRecord::Base
belongs_to :user
belongs_to :report, :polymorphic => true
end
class User < ActiveRecord::Base
...
has_many :search_reports
...
end
class TaskSearch < ActiveRecord::Base
...
has_many :search_reports, :as => :report
...
end
class LeadSearch < ActiveRecord::Base
...
has_many :search_reports, :as => :report
...
end
class One::BackendUser < ActiveRecord::Base
self.abstract_class = true
...
has_many :search_reports, :through => :user
has_many :task_reports, :through => :user, :source => :search_reports, :conditions => ["report_type = 'TaskSearch'"]
has_many :lead_reports, :through => :user, :source => :search_reports, :conditions => ["report_type = 'LeadSearch'"]
...
end
a = Agent.first
a.task_reports # returns task reports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment