Guest User

Untitled

a guest
Apr 16th, 2018
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. require 'rubygems'
  2. require 'active_record'
  3.  
  4. ActiveRecord::Base.logger = Logger.new("/home/nraja/Garage/FCBlog/log")
  5. ActiveRecord::Base.colorize_logging
  6.  
  7.  
  8. ActiveRecord::Base.establish_connection(
  9. :adapter => "mysql",
  10. :host => "127.0.0.1",
  11. :username => "fossconf",
  12. :password => "fossconf",
  13. :database => "fossconf"
  14. )
  15.  
  16.  
  17. ActiveRecord::Schema.define do
  18.  
  19. create_table :posts do |table|
  20. table.column :title, :string
  21. table.column :content, :string
  22. table.column :created_at, :datetime
  23. table.column :user_id, :string
  24. table.column :category_id, :integer
  25. end
  26.  
  27. create_table :comments do |table|
  28. table.column :post_id, :integer
  29. table.column :title, :string
  30. table.column :content, :string
  31. table.column :created_at, :datetime
  32. table.column :user_id, :integer
  33. end
  34.  
  35. create_table :users do |table|
  36. table.column :name, :string
  37. table.column :email, :string
  38. table.column :url, :string
  39. end
  40.  
  41. create_table :categories do |table|
  42. table.column :category, :string
  43. end
  44.  
  45. end
  46.  
  47.  
  48. class Post < ActiveRecord::Base
  49. has_many :comments
  50. belongs_to_many :categories
  51. belongs_to :user
  52. end
  53.  
  54. class Comment < ActiveRecord::Base
  55. belongs_to :user
  56. belongs_to :post
  57. end
  58.  
  59. class User < ActiveRecord::Base
  60. has_many :comments
  61. has_many :posts
  62. end
  63.  
  64. class Category < ActiveRecord::Base
  65. has_many :posts
  66. end
Add Comment
Please, Sign In to add comment