Skip to content

Commit 08e2300

Browse files
author
Rogelio Guzman
committedJan 26, 2012
Changed from habtm to has_many though
1 parent c5b63a1 commit 08e2300

6 files changed

+39
-3
lines changed
 

‎app/models/ruby_gem.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
class RubyGem < ActiveRecord::Base
2-
has_and_belongs_to_many :tutorials
2+
# has_and_belongs_to_many :tutorials
3+
has_many :ruby_gem_tutorials, dependent: :destroy
4+
has_many :tutorials, through: :ruby_gem_tutorials
5+
36
serialize :info, Hash
47
before_create :set_info
58

‎app/models/ruby_gem_tutorial.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class RubyGemTutorial < ActiveRecord::Base
2+
belongs_to :ruby_gem
3+
belongs_to :tutorial
4+
end

‎app/models/tutorial.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ class Tutorial < ActiveRecord::Base
33
attr_accessible :title, :body, :user_id, :ruby_gem_tokens, :estimated_time, :source_code, :repo_link
44

55
acts_as_markdown :body
6+
7+
# has_and_belongs_to_many :ruby_gems
8+
has_many :ruby_gem_tutorials, dependent: :destroy
9+
has_many :ruby_gems, through: :ruby_gem_tutorials
610

711
belongs_to :user, counter_cache: true
8-
has_and_belongs_to_many :ruby_gems
912
has_many :points, :dependent => :destroy
1013
attr_reader :ruby_gem_tokens
1114

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateRubyGemTutorials < ActiveRecord::Migration
2+
def change
3+
create_table :ruby_gem_tutorials do |t|
4+
t.integer :tutorial_id
5+
t.integer :ruby_gem_id
6+
7+
t.timestamps
8+
9+
end
10+
add_index :ruby_gem_tutorials, [:ruby_gem_id, :tutorial_id]
11+
end
12+
end

‎db/schema.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20120126172256) do
14+
ActiveRecord::Schema.define(:version => 20120126175716) do
1515

1616
create_table "authentications", :force => true do |t|
1717
t.integer "user_id"
@@ -28,6 +28,15 @@
2828
t.datetime "updated_at"
2929
end
3030

31+
create_table "ruby_gem_tutorials", :force => true do |t|
32+
t.integer "tutorial_id"
33+
t.integer "ruby_gem_id"
34+
t.datetime "created_at"
35+
t.datetime "updated_at"
36+
end
37+
38+
add_index "ruby_gem_tutorials", ["ruby_gem_id", "tutorial_id"], :name => "index_ruby_gem_tutorials_on_ruby_gem_id_and_tutorial_id"
39+
3140
create_table "ruby_gems", :force => true do |t|
3241
t.string "name"
3342
t.datetime "created_at"

‎spec/models/ruby_gem_tutorial_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'spec_helper'
2+
3+
describe RubyGemTutorial do
4+
pending "add some examples to (or delete) #{__FILE__}"
5+
end

0 commit comments

Comments
 (0)
Please sign in to comment.