diff options
author | Joe Sak <joe@joesak.com> | 2011-02-15 23:20:07 -0600 |
---|---|---|
committer | Joe Sak <joe@joesak.com> | 2011-02-15 23:23:17 -0600 |
commit | 652ecc4707f2e6ee019e1864179ffcaf76706ed2 (patch) | |
tree | db293583a180fb79902b1a4f2f50b25b8ce1caf2 /app | |
parent | 2b86be50d2c8e1299e729be6f90a03b4631956ba (diff) | |
download | refinerycms-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
Diffstat (limited to 'app')
-rw-r--r-- | app/models/blog_category.rb | 3 | ||||
-rw-r--r-- | app/models/blog_post.rb | 4 | ||||
-rw-r--r-- | app/models/categorization.rb | 5 |
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 |