mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
add some models
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
class Article < ActiveRecord::Base
|
||||
|
||||
has_many :comments, as: :commentable
|
||||
has_many :likes, as: :likable
|
||||
has_many :favorites, as: :favoritable
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
|
||||
has_many :likes, as: :likable
|
||||
belongs_to :commentable, polymorphic: true, counter_cache: :comments_count
|
||||
belongs_to :user
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Favorite < ActiveRecord::Base
|
||||
|
||||
belongs_to :favoritable, polymorphic: true, counter_cache: :favorites_count
|
||||
belongs_to :user
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Like < ActiveRecord::Base
|
||||
|
||||
belongs_to :likable, polymorphic:true, counter_cache: :likes_count
|
||||
belongs_to :user
|
||||
end
|
||||
@@ -1,2 +1,7 @@
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
has_many :comments
|
||||
has_many :likes
|
||||
has_many :favorites
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class WebPage < ActiveRecord::Base
|
||||
|
||||
has_many :comments, as: :commentable
|
||||
has_many :likes, as: :likable
|
||||
has_many :favorites, as: :favoritable
|
||||
end
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
default: &default
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
username: postgres
|
||||
username: twer
|
||||
# For details on connection pooling, see rails configuration guide
|
||||
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
||||
pool: 5
|
||||
@@ -82,5 +82,5 @@ test:
|
||||
production:
|
||||
<<: *default
|
||||
database: LibrX_production
|
||||
username: LibrX
|
||||
password: <%= ENV['LIBRX_DATABASE_PASSWORD'] %>
|
||||
username: twer
|
||||
password:
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateArticles < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :articles do |t|
|
||||
t.string :name
|
||||
t.string :url
|
||||
t.string :author
|
||||
t.string :content
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class CreateWebPages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :web_pages do |t|
|
||||
t.string :name
|
||||
t.string :url
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateComments < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :comments do |t|
|
||||
t.integer :user_id
|
||||
t.string :content
|
||||
t.integer :commentable_id
|
||||
t.string :commentable_type
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateLikes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :likes do |t|
|
||||
t.integer :user_id
|
||||
t.integer :likable_id
|
||||
t.string :likable_type
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateFavorites < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :favorites do |t|
|
||||
t.integer :user_id
|
||||
t.integer :favoritable_id
|
||||
t.string :favoritable_type
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
+42
-1
@@ -11,11 +11,45 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150722145422) do
|
||||
ActiveRecord::Schema.define(version: 20150723132842) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "articles", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "url"
|
||||
t.string "author"
|
||||
t.string "content"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "comments", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.string "content"
|
||||
t.integer "commentable_id"
|
||||
t.string "commentable_type"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "favorites", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "favoritable_id"
|
||||
t.string "favoritable_type"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "likes", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "likable_id"
|
||||
t.string "likable_type"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email"
|
||||
t.string "name"
|
||||
@@ -25,4 +59,11 @@ ActiveRecord::Schema.define(version: 20150722145422) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "web_pages", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "url"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name:
|
||||
url:
|
||||
author:
|
||||
content:
|
||||
|
||||
two:
|
||||
name:
|
||||
url:
|
||||
author:
|
||||
content:
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
content: MyString
|
||||
commentable_id: 1
|
||||
commentable_type: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
content: MyString
|
||||
commentable_id: 1
|
||||
commentable_type: MyString
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
favoritable_id: 1
|
||||
favoritable_type: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
favoritable_id: 1
|
||||
favoritable_type: MyString
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
likable_id: 1
|
||||
likable_type: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
likable_id: 1
|
||||
likable_type: MyString
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name:
|
||||
url:
|
||||
|
||||
two:
|
||||
name:
|
||||
url:
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArticleTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CommentTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class LikeTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class WebPageTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user