Skip to content

Instantly share code, notes, and snippets.

@alecslupu
Last active October 31, 2018 09:59
Show Gist options
  • Save alecslupu/5442354 to your computer and use it in GitHub Desktop.
Save alecslupu/5442354 to your computer and use it in GitHub Desktop.
class Task < ActiveRecord::Base
belongs_to :pending_tasks_in_project, :inverse_of => :pending_tasks,
:class_name => 'Project',:foreign_key => :project_id,
:counter_cache => :pending_tasks_count
belongs_to :opened_tasks_in_project, :inverse_of => :opened_tasks,
:class_name => 'Project',:foreign_key => :project_id,
:counter_cache => :opened_tasks_count
belongs_to :closed_tasks_in_project, :inverse_of => :closed_tasks,
:class_name => 'Project', :foreign_key => :project_id,
:counter_cache => :closed_tasks_count
end
class Project < ActiveRecord::Base
has_many :opened_tasks,
:class_name => 'Task',
:conditions => { :status => 'opened'}
has_many :pending_tasks,
:class_name => 'Task',
:conditions => { :status => 'pending'}
has_many :closed_tasks,
:class_name => 'Task',
:conditions => { :status => 'closed' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment