single-table inheritance 单表继承
type 字段在 Rails 中默认使用来做 STI(single-table inheritance),
当 type 作为普通字段来使用时,可以把SIT的列设置成别的列名(比如不存在的某个列)。 文档在这里
http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-inheritance_column,
使用下面的方法就是设置 STI 使用的列名,默认是‘type',既然不想使用 STI了,可以设置一个不太可能和以后的列名冲突的名字,比如使用 ’_disable‘。 比如可以在 Model 中设置为
self.inheritance_column = '_disable'
Defines the name of the table column which will store the class name on single-table inheritance situations.
The default inheritance column name is type, which means it's a reserved word inside Active Record. To be able to use single-table inheritance with another column name, or to use the column type in your own model for something else, you can set inheritance_column:
self.inheritance_column = 'zoink'
关于single table inheritance, 可以查看下面的文档
http://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html 以下是建表语句
class CreateSubjects < ActiveRecord::Migration[5.0]
def change
create_table :subjects do |t|
t.string :title, limit: 40
t.string :sub_title, limit: 40
t.string :categories, limit: 30
t.string :description, limit: 500
t.integer :status, limit: 1
t.integer :type, limit: 1
t.integer :use_default_image, limit: 1
t.integer :has_ranking_list, limit: 1 t.timestamps
end
end
end
single-table inheritance 单表继承的更多相关文章
- ActiveRecord-连接多张表之单表继承
ActiveRecord-连接多张表之单表继承 1. 基本概念 Rails提供了两种机制,可以将复杂的面向对象模型映射为关系模型,即所谓的单表继承(single-table inheritance)和 ...
- python flask_sqlalchemy 多态 polymorphic 实现单表继承
sqlalchemy 多态 polymorphic 实现单表继承 sqlaclchemy中的单表继续就是以一个模型类为基类,其他模型类继承基类,所有模型类的的数据都存一张表里面(也可以是多张,只不过基 ...
- SpringBoot系列——Spring-Data-JPA(究极进化版) 自动生成单表基础增、删、改、查接口
前言 我们在之前的实现了springboot与data-jpa的增.删.改.查简单使用(请戳:SpringBoot系列——Spring-Data-JPA),并实现了升级版(请戳:SpringBoot系 ...
- springdata 查询思路:基本的单表查询方法(id,sort) ---->较复杂的单表查询(注解方式,原生sql)--->实现继承类---->复杂的多表联合查询 onetomany
springdata 查询思路:基本的单表查询方法(id,sort) ---->较复杂的单表查询(注解方式,原生sql)--->实现继承类---->复杂的多表联合查询 onetoma ...
- element-ui 解决 table 里包含表单验证的问题!
实际项目中的场景,需要在table里做表单的验证,如图效果: 其实问题关键就在于如何给el-form-item动态绑定prop :prop="'tableData.' + scope.$in ...
- $Django 模板层(模板导入,继承)、 单表*详(增删改查,基于双下划线的查询)、static之静态文件配置
0在python脚本中使用django环境 import osif __name__ == '__main__': os.environ.setdefault("DJANGO_SETT ...
- 5.Inheritance Strategy(继承策略)【EFcode-first系列】
我们已经在code-first 约定一文中,已经知道了Code-First为每一个具体的类,创建数据表. 但是你可以自己利用继承设计领域类,面向对象的技术包含“has a”和“is a”的关系即,有什 ...
- Hadoop阅读笔记(三)——深入MapReduce排序和单表连接
继上篇了解了使用MapReduce计算平均数以及去重后,我们再来一探MapReduce在排序以及单表关联上的处理方法.在MapReduce系列的第一篇就有说过,MapReduce不仅是一种分布式的计算 ...
- MapReduce编程系列 — 5:单表关联
1.项目名称: 2.项目数据: chile parentTom LucyTom JackJone LucyJone JackLucy MaryLucy Ben ...
随机推荐
- jdbc java数据库连接 6)类路径读取——JdbcUtil的配置文件
之前的代码中,以下代码很多时候并不是固定的: private static String url = "jdbc:mysql://localhost:3306/day1029?useUnic ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 多软件系统集成缓存体系改进
由于我们同时开发多个大型应用系统同时系统有大量用户.高并发用户,平时访问系统的用户数量就有3万多人在线.需要对几十个系统进行持续优化改进,同时要增强信息系统的各种安全性. 如此多的系统.如此多的用户, ...
- 汇编语言标志位 含义 NV UP EI NG NZ AC PE CY
缩写原意: Overflow of = OV NV [No Overflow] Direction df = DN (decrement) UP (increment) Interrupt if = ...
- 第一章,阿里的Dubbo完美初级搭建,待续。。。
1.1 后台工程搭建分析 Web工程. Maven的常见打包方式:jar.war.pom Pom工程一般都是父工程,管理jar包的版本.maven插件的版本.统一的依赖管理.聚合工程. Taotao- ...
- 几个常用的CV知识点
刚结束一段实习,图像算法工程师.总结一下图像算法的几个基本的操作,图像操作算子各式各样,各显神通,光是滤波filter这一个专题就可以有很多的技巧和功能. 我从做过的两个小项目入手, 简单介绍一下该项 ...
- virtual memory exhausted: Cannot allocate memory
~$free total used free shared buffers cached Mem: 1017832 784328 233504 356 12844 14692 -/+ buffers/ ...
- 通过OnResultExecuted设置返回内容为JSONP
public class JsonpAttribute : ActionFilterAttribute { /// <summary> /// 在执行操作结果后更改返回结果 /// < ...
- 为Debian/Ubuntu的apt-get install添加自动补齐/完成功能
Debian/Ubuntu的apt-get太常用了,不过偶尔可能也会碰到不太熟悉,想不起来的包的名称,除了去debian packages去查找,另外的方法就是给Debian/Ubuntu添加自动补齐 ...
- 解决:Error: JAVA_HOME is not defined correctly
问题重现: Error: JAVA_HOME is not defined correctly. We cannot execute :/usr/lib/jvm/java-7-oracle 问题分析: ...
- gulp打包js/css时合并成一个文件时的顺序解决
1.可以使用插进gulp-order. 2.可以这样的写法: return gulp.src(['js/common.js','js/**/*.js']) .pipe(concat('build.js ...