Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

topics_property_type association and test passage.

  • Loading branch information...
commit e5b94cdd59425bfda7fddab0aaf0ed4997fe7bca 1 parent 0476dcf
@jdwyah authored
View
7 app/models/topic.rb
@@ -1,9 +1,12 @@
class Topic < ActiveRecord::Base
belongs_to :user
has_many :properties
- has_many :property_types
+ has_and_belongs_to_many :property_types, :class_name => 'PropertyType', :join_table => :topics_property_types
has_and_belongs_to_many :tags, :class_name => 'Topic', :join_table => :topics_topics, :foreign_key => :child_id, :association_foreign_key => :parent_id
has_and_belongs_to_many :topics, :class_name => 'Topic', :join_table => :topics_topics, :foreign_key => :parent_id, :association_foreign_key => :child_id
has_many :occurrences, :through => :topics_occurrences
-
+
+ def properties_to_use
+ tags.map(&:property_types).flatten
+ end
end
View
11 db/migrate/20090522131220_create_topic_topic_properties.rb
@@ -0,0 +1,11 @@
+class CreateTopicTopicProperties < ActiveRecord::Migration
+ def self.up
+ create_table :topics_property_types do |t|
+ t.integer :topic_id, :property_type_id
+ end
+ end
+
+ def self.down
+ drop_table :topics_property_types
+ end
+end
View
7 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090521204802) do
+ActiveRecord::Schema.define(:version => 20090522131220) do
create_table "occurrences", :force => true do |t|
t.string "name"
@@ -71,6 +71,11 @@
t.integer "occurrence_id"
end
+ create_table "topics_property_types", :force => true do |t|
+ t.integer "topic_id"
+ t.integer "property_type_id"
+ end
+
create_table "topics_topics", :id => false, :force => true do |t|
t.integer "parent_id"
t.integer "child_id"
View
4 test/unit/topic_test.rb
@@ -21,8 +21,8 @@ class TopicTest < ActiveSupport::TestCase
end
should "books should have dates read " do
- assert_equals [@date_read], @book.property_types
- assert_equals [@date_read], @crime_and_punishment.properties_to_use
+ assert_equal [@date_read], @book.property_types
+ assert_equal [@date_read], @crime_and_punishment.properties_to_use
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.