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
相关推荐
As part of the Syngress Basics series, The Basics of Information Security provides you with fundamental knowledge of information security in both theoretical and practical aspects. It covers the basic...
An easy introduction to Computational Fluid Dynamics.... Covers the basics - grid generation, numerics, incompressible flow and supersonic flow. Motivates the reader with many examples.
Gradle Beyond the Basics
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 ...
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 ...
The Basics of Hacking and Penetration Testing.pdf
The Basics of Cloud Computing
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 ...
Learning the basics of a modeling technique is not the same as learning how to use and apply it. To develop a data model of an organization is to gain insights into its nature that do not come easily....
This book provides a clear introduction to ... Practical examples of the applications of these techniques are described and also the importance of diffraction in the performance of optical instruments.
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 ...
网上唯一的《Gradle Beyond the Basics》中文版。
A tour of git: the basics A tour of git: the basics 2.0 Copyright This document is a modified version of a document originally titled "Distributed revision control with Mercurial" and originally ...
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 ...
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 ...
Gradle Beyond the Basics
[Gradle.Beyond.the.Basics(2013.7)].Tim.Berglund.文字版
极好的SAS入门教程 Beyond the Basics Book-FINAL(英文版)
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-...
学习aspen软件的教程,很实用, 希望对需要的朋友有用