Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Add Projects with a HABTM relation to People
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jul 27, 2014
1 parent 9274b40 commit 5738ccc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Person < ActiveRecord::Base
authenticates_with_sorcery!

has_and_belongs_to_many :projects

validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
Expand Down
3 changes: 3 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Project < ActiveRecord::Base
has_and_belongs_to_many :people
end
14 changes: 14 additions & 0 deletions db/migrate/20140727135545_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :name

t.timestamps
end

create_join_table :people, :projects, id: false do |t|
t.index :person_id
t.index :project_id
end
end
end
16 changes: 15 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140726092933) do
ActiveRecord::Schema.define(version: 20140727135545) do

create_table "people", force: true do |t|
t.string "login", null: false
Expand Down Expand Up @@ -45,4 +45,18 @@

add_index "people", ["email"], name: "index_people_on_email", unique: true

create_table "people_projects", id: false, force: true do |t|
t.integer "person_id", null: false
t.integer "project_id", null: false
end

add_index "people_projects", ["person_id"], name: "index_people_projects_on_person_id"
add_index "people_projects", ["project_id"], name: "index_people_projects_on_project_id"

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

end
7 changes: 7 additions & 0 deletions test/fixtures/projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString

two:
name: MyString
7 changes: 7 additions & 0 deletions test/models/project_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ProjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 5738ccc

Please sign in to comment.