post.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. module WP25
  2.   class Post < ActiveRecord::Base
  3.     set_table_name 'wp_posts'
  4.     set_primary_key 'ID'
  5.     establish_connection configurations['wp25']
  6.     has_many :comments, :foreign_key => 'comment_parent', :class_name => 'WP25::Comment'
  7.     has_many :term_relationships, :foreign_key => 'object_id'
  8.     has_many :term_taxonomies, :through => :term_relationships,
  9.              :class_name => 'WP25::TermTaxonomy'
  10.     def categories
  11.       term_taxonomies.inject([]) do |list, taxonomy|
  12.         if taxonomy.taxonomy.eql?('category')
  13.           list << taxonomy.term.name
  14.         end
  15.         list
  16.       end
  17.     end
  18.     def tags
  19.       term_taxonomies.inject([]) do |list, taxonomy|
  20.         if taxonomy.taxonomy.eql?('post_tag')
  21.           list << taxonomy.term.name
  22.         end
  23.         list
  24.       end
  25.     end
  26.     def comments
  27.       WP25::Comment.find_all_by_comment_post_ID(self.ID)
  28.     end
  29.     
  30.     def self.prefix=(prefix)
  31.       set_table_name "#{prefix}_posts"
  32.     end
  33.   end
  34. end