Skip to content

Instantly share code, notes, and snippets.

@moustafasamir
Created March 5, 2013 13:30
Show Gist options
  • Save moustafasamir/5090301 to your computer and use it in GitHub Desktop.
Save moustafasamir/5090301 to your computer and use it in GitHub Desktop.
def Document < ActiveRecord::Base
belongs_to :user , :counter_cache => true
belongs_to :user , :inverse_of => :draft_docs , :counter_cache => true
belongs_to :user , :inverse_of => :published_docs, :counter_cache => true
belongs_to :user , :inverse_of => :private_docs , :counter_cache => true
end
def User < ActiveRecord::Base
has_many :documents
has_many :draft_docs , :class_name => 'Document', :conditions => { :status => 'draft' }
has_many :published_docs , :class_name => 'Document', :conditions => { :status => 'published' }
has_many :private_docs , :class_name => 'Document', :conditions => { :status => 'private' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment