<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Class: ActiveRecord::Base</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript">
// <![CDATA[
function popupCode( url ) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
function toggleCode( id ) {
if ( document.getElementById )
elem = document.getElementById( id );
else if ( document.all )
elem = eval( "document.all." + id );
else
return false;
elemStyle = elem.style;
if ( elemStyle.display != "block" ) {
elemStyle.display = "block"
} else {
elemStyle.display = "none"
}
return true;
}
// Make codeblocks hidden by default
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
// ]]>
</script>
</head>
<body>
<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td><strong>Class</strong></td>
<td class="class-name-in-header">ActiveRecord::Base</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../../files/vendor/rails/activerecord/lib/active_record/base_rb.html">
vendor/rails/activerecord/lib/active_record/base.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/openbase_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/openbase_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sybase_adapter_rb.html">
vendor/rails/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/deprecated_finders_rb.html">
vendor/rails/activerecord/lib/active_record/deprecated_finders.rb
</a>
<br />
<a href="../../files/vendor/rails/activerecord/lib/active_record/query_cache_rb.html">
vendor/rails/activerecord/lib/active_record/query_cache.rb
</a>
<br />
</td>
</tr>
<tr class="top-aligned-row">
<td><strong>Parent:</strong></td>
<td>
Object
</td>
</tr>
</table>
</div>
<!-- banner header -->
<div id="bodyContent">
<div id="contextContent">
<div id="description">
<p>
Active Record objects don‘t specify their <a
href="Base.html#M001069">attributes</a> directly, but rather infer them
from the table definition with which they‘re linked. Adding,
removing, and changing <a href="Base.html#M001069">attributes</a> and their
type is done directly in the database. Any change is instantly reflected in
the Active Record objects. The mapping that binds a given Active Record
class to a certain database table will happen automatically in most common
cases, but can be overwritten for the uncommon ones.
</p>
<p>
See the mapping rules in <a href="Base.html#M001022">table_name</a> and the
full example in <a href="../../files/README.html">files/README.html</a> for
more insight.
</p>
<h2>Creation</h2>
<p>
Active Records accept constructor parameters either in a <a
href="Base.html#M001077">hash</a> or as a block. The <a
href="Base.html#M001077">hash</a> method is especially useful when
you‘re receiving the data from somewhere else, like a HTTP request.
It works like this:
</p>
<pre>
user = User.new(:name => "David", :occupation => "Code Artist")
user.name # => "David"
</pre>
<p>
You can also use block initialization:
</p>
<pre>
user = User.new do |u|
u.name = "David"
u.occupation = "Code Artist"
end
</pre>
<p>
And of course you can just <a href="Base.html#M001008">create</a> a bare
object and specify the <a href="Base.html#M001069">attributes</a> after the
fact:
</p>
<pre>
user = User.new
user.name = "David"
user.occupation = "Code Artist"
</pre>
<h2>Conditions</h2>
<p>
Conditions can either be specified as a string, array, or <a
href="Base.html#M001077">hash</a> representing the WHERE-part of an SQL
statement. The array form is to be used when the condition input is tainted
and requires sanitization. The string form can be used for statements that
don‘t involve tainted data. The <a href="Base.html#M001077">hash</a>
form works much like the array form, except only equality and range is
possible. Examples:
</p>
<pre>
class User < ActiveRecord::Base
def self.authenticate_unsafely(user_name, password)
find(:first, :conditions => "user_name = '#{user_name}' AND password = '#{password}'")
end
def self.authenticate_safely(user_name, password)
find(:first, :conditions => [ "user_name = ? AND password = ?", user_name, password ])
end
def self.authenticate_safely_simply(user_name, password)
find(:first, :conditi
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
rails文档API (441个子文件)
rdoc-style.css 4KB
Base.html 199KB
CHANGELOG.html 180KB
CHANGELOG.html 172KB
fr_method_index.html 148KB
Selector.html 101KB
Base.html 91KB
ClassMethods.html 83KB
UTF8Handler.html 75KB
SQLServerAdapter.html 69KB
ClassMethods.html 66KB
SelectorAssertions.html 62KB
FrontBaseAdapter.html 60KB
DateHelper.html 60KB
PrototypeHelper.html 56KB
AbstractRequest.html 55KB
ClassMethods.html 51KB
TextHelper.html 51KB
Calculations.html 49KB
UrlHelper.html 49KB
FormOptionsHelper.html 45KB
fr_file_index.html 45KB
PostgreSQLAdapter.html 43KB
CHANGELOG.html 42KB
CHANGELOG.html 42KB
DB2Adapter.html 38KB
SchemaStatements.html 38KB
TimeZone.html 37KB
Column.html 37KB
GeneratorMethods.html 37KB
Session.html 35KB
Errors.html 35KB
FormTagHelper.html 35KB
TestProcess.html 34KB
Fixtures.html 34KB
FormHelper.html 32KB
Inflector.html 32KB
JavaScriptMacrosHelper.html 31KB
DatabaseStatements.html 31KB
AssetTagHelper.html 31KB
XmlSimple.html 30KB
ResponseAssertions.html 29KB
Callbacks.html 27KB
Breakpoint.html 26KB
NumberHelper.html 26KB
AbstractAdapter.html 25KB
JavaScriptHelper.html 25KB
OracleAdapter.html 25KB
Migration.html 24KB
ClassMethods.html 24KB
Base.html 24KB
ActiveRecordHelper.html 23KB
Inflections.html 23KB
Routing.html 23KB
InstanceMethods.html 23KB
Chars.html 22KB
InstanceMethods.html 22KB
Type.html 22KB
XmlMarkup.html 21KB
Paginator.html 21KB
Page.html 21KB
HashWithIndifferentAccess.html 21KB
Fragments.html 21KB
README.html 19KB
fr_class_index.html 19KB
Time.html 19KB
Method.html 18KB
MysqlAdapter.html 18KB
Conversions.html 18KB
Validations.html 17KB
OpenBaseAdapter.html 17KB
RoutingAssertions.html 17KB
FirebirdAdapter.html 16KB
README.html 16KB
TableDefinition.html 16KB
CHANGELOG.html 16KB
Pagination.html 16KB
SybaseAdapterContext.html 15KB
Quoting.html 15KB
CompiledTemplates.html 15KB
Resources.html 15KB
CHANGELOG.html 15KB
OCI8AutoRecover.html 15KB
Streaming.html 15KB
Conversions.html 15KB
ClassMethods.html 15KB
ScriptaculousHelper.html 14KB
Rescue.html 14KB
Inflections.html 14KB
Base.html 14KB
Observer.html 14KB
PaginationHelper.html 14KB
README.html 14KB
Bytes.html 13KB
ClassMethods.html 13KB
ClassMethods.html 13KB
MacroReflection.html 13KB
README.html 13KB
IntegrationTest.html 13KB
ClassMethods.html 13KB
共 441 条
- 1
- 2
- 3
- 4
- 5
资源评论
ww_213_ww
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功