Add the has_many_polymorphs plugin
[cs356-p2-videostore.git] / vendor / plugins / has_many_polymorphs / examples / hmph.rb
1 require 'camping'
2 require 'has_many_polymorphs'
3
4 Camping.goes :Hmph
5
6 module Hmph::Models
7   class GuestsKennel < Base
8     belongs_to :kennel
9     belongs_to :guest, :polymorphic => true
10   end
11
12   class Dog < Base
13   end
14
15   class Cat < Base
16   end
17
18   class Bird < Base
19   end
20   
21   class Kennel < Base
22     has_many_polymorphs :guests, 
23       :from => [:dogs, :cats, :birds],
24       :through => :guests_kennels,
25       :namespace => :"hmph/models/"      
26   end  
27
28   class InitialSchema < V 1.0
29     def self.up
30       create_table :hmph_kennels do |t|
31         t.column :created_at, :datetime
32         t.column :modified_at, :datetime
33         t.column :name, :string, :default => 'Anonymous Kennel'
34       end
35
36       create_table :hmph_guests_kennels do |t|
37         t.column :guest_id, :integer
38         t.column :guest_type, :string
39         t.column :kennel_id, :integer
40       end
41
42       create_table :hmph_dogs do |t|
43         t.column :name, :string, :default => 'Fido'
44       end
45
46       create_table :hmph_cats do |t|
47         t.column :name, :string, :default => 'Morris'
48       end
49
50       create_table :hmph_birds do |t|
51         t.column :name, :string, :default => 'Polly'
52       end
53     end
54
55     def self.down
56       drop_table :hmph_kennels
57       drop_table :hmph_guests_kennels
58       drop_table :hmph_dogs
59       drop_table :hmph_cats
60       drop_table :hmph_birds
61     end
62   end
63 end
64
65 module Hmph::Controllers
66 end
67
68 module Hmph::Views
69 end