`
jiajie0531
  • 浏览: 29396 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Active Record Basics 4 Overriding the Naming Conventions

阅读更多

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

0
0
分享到:
评论

相关推荐

    Hadoop from the beginning: 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 ...

    Computational Fluid Dynamics: The Basics with Applications 高清.pdf版

    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

    The Basics of Cloud Computing

    Pro ActiveRecord Databases

    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 Process Improvement 1st Edition

    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 Beyond the Basics #### 知识点一:Gradle 概述 - **定义与背景**:Gradle 是一款基于 Java 开发的构建工具,它采用了 Groovy 语言来编写构建脚本,同时也支持使用 Kotlin 编写构建脚本。Gradle 能够很...

    The.Art.of.Go.Basics.pdf

    《The Art of Go: Basics》是一本面向聪明的编程初学者的电子书,旨在介绍Go语言的基础知识。Go语言是一种流行的编程语言,主要被用于Web后端和服务器端编程,但其用途也在不断扩大。Go语言因其简单性、易学性、安全...

    Teach Yourself the Basics of Aspen Plus

    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 ...

    英文原版-Learning Radiology Recognizing the Basics 3rd Edition

    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(2013.7)].Tim.Berglund.文字版

    ### Gradle Beyond the Basics #### 书名及作者介绍 《Gradle Beyond the Basics》由Tim Berglund编写,于2013年7月由O'Reilly Media, Inc.出版。该书是针对已经了解Gradle基础知识的读者,旨在帮助他们深入掌握...

    人在回路机器学习Human-in-the-Loop_Machine_Learning.pdf

    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

    《 Beginning jQuery:From the Basics of jQuery to Writing your Own Plug-ins》是Jack Franklin和Russ Ferguson合著的一本关于jQuery的入门教程。这本书旨在帮助读者从零基础开始,逐步掌握jQuery的核心概念,并...

    Active Directory Cookbook, 3rd Edition.pdf

    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 #### 标题与描述解析 - **标题**:“Gradle Beyond the Basics” - **描述**:“Gradle Beyond the Basics” 这两个字段实际上提供的信息是一致的,都指向了一本名为《Gradle ...

    Teach_Yourself_the_Basics_of_Aspen_Plus.pdf

    学习aspen软件的教程,很实用, 希望对需要的朋友有用

    Introducing ZFS on Linux Understand the Basics of Storage with ZFS 无水印原版pdf

    Introducing ZFS on Linux Understand the Basics of Storage with ZFS 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请...

Global site tag (gtag.js) - Google Analytics