Permalink
Browse files

topics_property_type association and test passage.

  • Loading branch information...
jdwyah committed May 22, 2009
1 parent 0476dcf commit e5b94cdd59425bfda7fddab0aaf0ed4997fe7bca
Showing with 24 additions and 5 deletions.
  1. +5 −2 app/models/topic.rb
  2. +11 −0 db/migrate/20090522131220_create_topic_topic_properties.rb
  3. +6 −1 db/schema.rb
  4. +2 −2 test/unit/topic_test.rb
View
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit e5b94cd

Please sign in to comment.