version: rails4
4 重写命名约定
如果你需要遵循一个不同的命名约定,或者需要在你的Rails应用系统中使用一个遗留的数据将会怎么样?没有问题,你能够容易地重写默认的约定。
你能够使用 ActiveRecord::Base.table_name=方法来指明数据表名,类似于下文:
classProduct < ActiveRecord::Base self.table_name = "PRODUCT" end |
如果你这样子写了,你就能够去手动地定义类名,在你的测试定义中用set_fixture_class方法来集合fixtures(class_name.yml):
classFunnyJoke < ActiveSupport::TestCase set_fixture_class funny_jokes: Joke fixtures :funny_jokes ... end |
同样能够重写列,应该被使用的如同数据表的主键,使用ActiveRecord::Base.primary_key=方法:
classProduct < ActiveRecord::Base self.primary_key = "product_id" end |
original: http://guides.rubyonrails.org/active_record_basics.html#overriding-the-naming-conventions
相关推荐
The author helps you familiarize yourself with the various commands that you can use to perform various tasks within the Hadoop system. The author also helps you know how to write MapReduce programs ...
An easy introduction to Computational Fluid Dynamics.... Covers the basics - grid generation, numerics, incompressible flow and supersonic flow. Motivates the reader with many examples.
The Basics of Cloud Computing
And almost all of those books actually do a great job of introducing you to the basics of Active Record; they go a long way toward getting you started with the library. However, because they ...
In addition, it helps individuals who have worked in stale- or siloed-thinking enterprises make the transition to a process or improvement-oriented culture and teaches those who are unfamiliar with ...
### Gradle Beyond the Basics #### 知识点一:Gradle 概述 - **定义与背景**:Gradle 是一款基于 Java 开发的构建工具,它采用了 Groovy 语言来编写构建脚本,同时也支持使用 Kotlin 编写构建脚本。Gradle 能够很...
《The Art of Go: Basics》是一本面向聪明的编程初学者的电子书,旨在介绍Go语言的基础知识。Go语言是一种流行的编程语言,主要被用于Web后端和服务器端编程,但其用途也在不断扩大。Go语言因其简单性、易学性、安全...
engineering groups, and plant startup and support operations, the most frequently referenced documents were process flow diagrams (PFDs), which contain the material and energy balances and the basic ...
Machine Learning: The Basics 机器学习基础 英文完整 带目录
A must-have for anyone who will be required to read and interpret common radiologic images, Learning Radiology: Recognizing the Basics is an image-filled, practical, and easy-to-read introduction to ...
Covers the basics of searching Active Directory: creating, modifying, and deleting objects, using LDAP controls, and importing and exporting data using LDAP Data Interchange Format (LDIF) and comma-...
### Gradle Beyond the Basics #### 书名及作者介绍 《Gradle Beyond the Basics》由Tim Berglund编写,于2013年7月由O'Reilly Media, Inc.出版。该书是针对已经了解Gradle基础知识的读者,旨在帮助他们深入掌握...
Human-in-the-Loop Machine Learning is a practical guide to optimizing the entire machine learning process, including techniques for annotation, active learning, transfer learning, and using machine ...
《 Beginning jQuery:From the Basics of jQuery to Writing your Own Plug-ins》是Jack Franklin和Russ Ferguson合著的一本关于jQuery的入门教程。这本书旨在帮助读者从零基础开始,逐步掌握jQuery的核心概念,并...
### Gradle Beyond the Basics #### 标题与描述解析 - **标题**:“Gradle Beyond the Basics” - **描述**:“Gradle Beyond the Basics” 这两个字段实际上提供的信息是一致的,都指向了一本名为《Gradle ...
学习aspen软件的教程,很实用, 希望对需要的朋友有用