寂静小站2.0的Model之Dict及其它

Published at 5 months ago

 Dict就是字典的意思,现在暂时冒充Tag的功能,计划今后会把类似的Dict合并成一个Tag。

Dict的结构如下:

create_table "dicts", :force => true do |t|
    t.text     "name"
    t.text     "slug"
    t.integer  "count"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

方法如下:

has_many :post_dict
  
  def get_posts
    posts_id = Post.find(
      :conditions => ['post_dicts.dict_id = ?', self.id],
      :include => :post_dict
    )
  end

除了Dict和Post外,就剩下PostFrom和PostDict的结构还没介绍,它们的结构分别为:

create_table "post_dicts", :force => true do |t|
    t.integer  "post_id"
    t.integer  "dict_id"
    t.integer  "count"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "post_froms", :force => true do |t|
    t.integer  "post_id"
    t.text     "table"
    t.integer  "pid"
    t.text     "url"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

相对于Post,这些都简单很多

#Ruby on Rails

@http://zfben.com/blog/寂静小站2.0的Model之Dict及其它