From 100ab5bd431e1cf9f4fdf08c8724918f482c4684 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 15 Jan 2011 23:39:32 +0530 Subject: Documented the except and only conditions in the guides. Took the cue from Jordi Ramero's commit (b31ef7ee83f3fe808f7534172ce2bf22ef6c7cc0) --- .../guides/source/active_record_querying.textile | 32 ++++++++++++++++++++-- 1 file 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. -
- 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: + + +Post.where('id > 10').limit(20).order('id asc').except(:order) + + +The SQL that would be executed: + + +SELECT * FROM posts WHERE id > 10 LIMIT 20 + + +You can also override conditions using the +only+ method. + +For example: + + +Post.where('id > 10').limit(20).order('id desc').only(:order, :where) + + +The SQL that would be executed: + + +SELECT * FROM posts WHERE id > 10 ORDER BY id DESC + + 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. -- cgit v1.2.3