分享 推荐一个 Rails 5 Tips 的博客

springwq · April 14, 2016 · Last by pathbox replied at April 14, 2016 · 2275 hits

最近在用 Rails 5 写一个新项目,由于 Rails 5 makes belongs_to association required by default, 我在实现一个 self-referrence 的 model 出现了点问题。

class Category < ApplicationRecord
  has_many :child_categories, class_name: "Category", foreign_key: "parent_id", dependent: :delete_all
  belongs_to :parent_categories, class_name: "Category", foreign_key: "parent_id"
end

虽然可以在 config 里关闭这个特性,但还是希望希望保持这个特性将来可以少写一点 validation,于是我把 belongs_to 关联去掉了。。。

Google 搜到这个博客,挺有料的,第一篇 Rails 5 相关的博客,从 2015 年 10 月份就开始了。

之前从 rubyweekly 一篇文章里收藏了这个 blog

You need to Sign in before reply, if you don't have an account, please Sign up first.