aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/blog_category.rb3
-rw-r--r--app/models/blog_post.rb4
-rw-r--r--app/models/categorization.rb5
3 files changed, 10 insertions, 2 deletions
diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb
index 8ffe834..fbd5465 100644
--- a/app/models/blog_category.rb
+++ b/app/models/blog_category.rb
@@ -1,6 +1,7 @@
class BlogCategory < ActiveRecord::Base
- has_and_belongs_to_many :posts, :class_name => 'BlogPost'
+ has_many :categorizations
+ has_many :posts, :through => :categorizations, :source => :blog_post, :order => 'published_at DESC'
acts_as_indexed :fields => [:title]
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index 60d982a..1d01a20 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -1,7 +1,9 @@
class BlogPost < ActiveRecord::Base
has_many :comments, :class_name => 'BlogComment', :dependent => :destroy
- has_and_belongs_to_many :categories, :class_name => 'BlogCategory'
+
+ has_many :categorizations
+ has_many :categories, :through => :categorizations, :source => :blog_category
acts_as_indexed :fields => [:title, :body]
diff --git a/app/models/categorization.rb b/app/models/categorization.rb
new file mode 100644
index 0000000..32e9967
--- /dev/null
+++ b/app/models/categorization.rb
@@ -0,0 +1,5 @@
+class Categorization < ActiveRecord::Base
+ set_table_name 'blog_categories_blog_posts'
+ belongs_to :blog_post
+ belongs_to :blog_category
+end \ No newline at end of file