Skip to content

Commit

Permalink
Merge pull request #4 from devfu/items
Browse files Browse the repository at this point in the history
relate Items & CompartmentsItems
  • Loading branch information
dalegregory committed Apr 16, 2012
2 parents af255ec + a8db0cc commit ac19450
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/compartments_items.rb
Expand Up @@ -9,8 +9,15 @@ class CompartmentsItems < ActiveRecord::Base
:operation,
:quantity_limit

belongs_to :item

validates :compartment_type, presence: true
validates :item_code, presence: true
validates :operation, inclusion: { in: Modula::OPERATIONS }

def item_code= code
self[:item_code] = code
self.item = Item.find_by_code code
end

end
3 changes: 3 additions & 0 deletions app/models/item.rb
Expand Up @@ -4,6 +4,9 @@ class Item < ActiveRecord::Base
:description,
:operation

has_many :compartments_items

validates :code, presence: true
validates :operation, inclusion: { in: Modula::OPERATIONS }

end
2 changes: 2 additions & 0 deletions db/migrate/20120413003642_create_compartments_items.rb
Expand Up @@ -2,6 +2,8 @@ class CreateCompartmentsItems < ActiveRecord::Migration

def change
create_table :compartments_items do |t|
t.belongs_to :item

t.decimal :capacity
t.decimal :quantity_limit
t.integer :height
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -14,6 +14,7 @@
ActiveRecord::Schema.define(:version => 20120413004841) do

create_table "compartments_items", :force => true do |t|
t.integer "item_id"
t.decimal "capacity", :precision => 10, :scale => 0
t.decimal "quantity_limit", :precision => 10, :scale => 0
t.integer "height"
Expand Down

0 comments on commit ac19450

Please sign in to comment.