diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-01-15 23:39:32 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-01-15 23:39:44 +0530 |
commit | 100ab5bd431e1cf9f4fdf08c8724918f482c4684 (patch) | |
tree | 4ebaf854ade7ac764d6753739e63df5321186a0e /railties/guides/source | |
parent | 1a051259b426d624e846f76c3fc6011693603e55 (diff) | |
download | rails-100ab5bd431e1cf9f4fdf08c8724918f482c4684.tar.gz rails-100ab5bd431e1cf9f4fdf08c8724918f482c4684.tar.bz2 rails-100ab5bd431e1cf9f4fdf08c8724918f482c4684.zip |
Documented the except and only conditions in the guides. Took the cue from Jordi Ramero's commit (b31ef7ee83f3fe808f7534172ce2bf22ef6c7cc0)
Diffstat (limited to 'railties/guides/source')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 22358029d4..64a68f7592 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -19,8 +19,6 @@ Code examples throughout this guide will refer to one or more of the following m TIP: All of the following models use +id+ as the primary key, unless specified otherwise. -<br /> - <ruby> class Client < ActiveRecord::Base has_one :address @@ -461,6 +459,36 @@ SELECT * FROM orders GROUP BY date(created_at) HAVING created_at > '2009-01-15' This will return single order objects for each day, but only for the last month. +h3. Overriding Conditions + +You can specify certain conditions to be excepted by using the +except+ method. + +For example: + +<ruby> +Post.where('id > 10').limit(20).order('id asc').except(:order) +</ruby> + +The SQL that would be executed: + +<sql> +SELECT * FROM posts WHERE id > 10 LIMIT 20 +</sql> + +You can also override conditions using the +only+ method. + +For example: + +<ruby> +Post.where('id > 10').limit(20).order('id desc').only(:order, :where) +</ruby> + +The SQL that would be executed: + +<sql> +SELECT * FROM posts WHERE id > 10 ORDER BY id DESC +</sql> + h3. Readonly Objects Active Record provides +readonly+ method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception. |