Advertisement
Guest User

Project Management

a guest
Jun 17th, 2010
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.43 KB | None | 0 0
  1. Project Model
  2.  
  3. class Project < ActiveRecord::Base
  4.   has_and_belongs_to_many :clients
  5. end
  6.  
  7. Clients Model
  8.  
  9. class Client < ActiveRecord::Base
  10.   has_one :user, :dependent => :destroy
  11.   has_and_belongs_to_many :projects
  12. end
  13.  
  14. clients_projects migration
  15.  
  16. class CreateClientsProjects < ActiveRecord::Migration
  17.   def self.up
  18.     create_table :clients_projects, :id => false do |t|
  19.       t.column :client_id, :integer
  20.       t.column :project_id, :integer
  21.     end
  22.   end
  23.  
  24.   def self.down
  25.     drop_table :clients_projects
  26.   end
  27. end
  28.  
  29. Clients Migration
  30.  
  31. class CreateClients < ActiveRecord::Migration
  32.   def self.up
  33.     create_table :clients do |t|
  34.       t.string :name, :null => false, :limit => '100'
  35.       t.string :contact_name, :null => true, :limit =>'100'
  36.       t.string :contact_last_name, :null => false, :limit => '100'
  37.       t.string :contact_email, :null => false, :limit => '100'
  38.       t.string :contact_phone, :null => false, :limit => '100'
  39.       t.boolean :admin, :default => false
  40.  
  41.       t.timestamps
  42.     end
  43.    
  44.  
  45.   def self.down
  46.     drop_table :clients
  47.   end
  48. end
  49.  
  50.  
  51. Projects Migration
  52.  
  53. class CreateProjects < ActiveRecord::Migration
  54.   def self.up
  55.     create_table :projects do |t|
  56.       t.string :name, :null => false, :limit => '100'
  57.       t.integer :duration, :null => false
  58.       t.integer :progress, :default => 0
  59.  
  60.       t.timestamps
  61.     end
  62.   end
  63.  
  64.   def self.down
  65.     drop_table :projects
  66.   end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement