Skip to content

Commit

Permalink
adding models
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwallace committed Sep 6, 2011
1 parent b52302d commit 46fbb70
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Post < ActiveRecord::Base
belongs_to :user

scope :published, where(:published => true)
scope :latest, order('created_at DESC')
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ActiveRecord::Base
has_many :posts
end
9 changes: 9 additions & 0 deletions db/migrate/20110906020806_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20110906020928_create_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.integer :user_id
t.boolean :published, :default => 0

t.timestamps
end
end
end
31 changes: 31 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110906020928) do

create_table "posts", :force => true do |t|
t.string "title"
t.text "body"
t.integer "user_id"
t.boolean "published", :default => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

end
5 changes: 5 additions & 0 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Post do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe User do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 46fbb70

Please sign in to comment.