Ruby on Rails 创建模型
例子
User通过运行创建一个模型(让我们称之为):
$ rails g model User
这将生成文件app/models/user.rb:
class User include Mongoid::Document end
这就是您拥有模型所需的全部内容(尽管只是一个id字段)。与不同ActiveRecord,没有迁移文件。模型的所有数据库信息都包含在模型文件中。
生成模型时,时间戳不会自动包含在模型中。要添加created_at和updated_at到您的模型,请添加
include Mongoid::Timestamps
到您下面的模型,includeMongoid::Document如下所示:
class User include Mongoid::Document include Mongoid::Timestamps end
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短