Created
October 18, 2012 12:17
-
-
Save anonymous/3911436 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Organization < ActiveRecord::Base | |
acts_as_nested_set | |
attr_accessible :name, :location_id, :parent_id | |
belongs_to :location | |
has_many :batches | |
has_many :org_prod_relationships, dependent: :destroy | |
has_many :products, through: :org_prod_relationships | |
validates :name, presence: true | |
validates :location_id, presence: true | |
def has_product?(prod) | |
org_prod_relationships.find_by_product_id(prod.id) | |
end | |
def add_product!(prod) | |
org_prod_relationships.create!(product_id: prod.id) | |
end | |
def publish_product!(prod) | |
self.descendants.each do |d| | |
d.add_product!(prod) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment