aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Sak <joe@joesak.com>2011-02-15 23:20:07 -0600
committerJoe Sak <joe@joesak.com>2011-02-15 23:23:17 -0600
commit652ecc4707f2e6ee019e1864179ffcaf76706ed2 (patch)
treedb293583a180fb79902b1a4f2f50b25b8ce1caf2
parent2b86be50d2c8e1299e729be6f90a03b4631956ba (diff)
downloadrefinerycms-blog-652ecc4707f2e6ee019e1864179ffcaf76706ed2.tar.gz
refinerycms-blog-652ecc4707f2e6ee019e1864179ffcaf76706ed2.tar.bz2
refinerycms-blog-652ecc4707f2e6ee019e1864179ffcaf76706ed2.zip
Closes GH-37. Move habtm assn to a has_many :through so posts can be ordered by published_at DESC on category#show view
-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