diff options
author | CassioMarques <cassiommc@gmail.com> | 2008-11-05 22:09:57 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2008-11-05 22:09:57 -0200 |
commit | 414d482978168e22b58afab1583f54a77cf74ca8 (patch) | |
tree | 3a558655b9d5cffa0b80b848680539a0fcad4d06 /railties/doc | |
parent | 0306fe53edf5c92055c77fe295cece18910fc82b (diff) | |
download | rails-414d482978168e22b58afab1583f54a77cf74ca8.tar.gz rails-414d482978168e22b58afab1583f54a77cf74ca8.tar.bz2 rails-414d482978168e22b58afab1583f54a77cf74ca8.zip |
AR validations and callbacks - Chaper 2: When does validations happens?
Diffstat (limited to 'railties/doc')
-rw-r--r-- | railties/doc/guides/html/activerecord_validations_callbacks.html | 11 | ||||
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index bac96beab0..f6c8fc668e 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -202,6 +202,9 @@ ul#navMain { <a href="#_motivations_to_validate_your_active_record_objects">Motivations to validate your Active Record objects</a> </li> <li> + <a href="#_when_does_validation_happens">When does validation happens?</a> + </li> + <li> <a href="#_credits">Credits</a> </li> <li> @@ -272,10 +275,14 @@ Using validation directly into your Active Record classes ensures that only vali </li>
</ul></div>
</div>
-<h2 id="_credits">2. Credits</h2>
+<h2 id="_when_does_validation_happens">2. When does validation happens?</h2>
+<div class="sectionbody">
+<div class="para"><p>There are two kinds of Active Record objects: those that correspond to a row inside your database and those who do not. When you create a fresh object, using the <tt>new</tt> method, that object does not belong to the database yet. Once you call <tt>save</tt> upon that object it'll be recorded to it's table. Active Record uses the <tt>new_record?</tt> instance method to discover if an object is already in the database or not. Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either <tt>save</tt>, <tt>update_attribute</tt> or <tt>update_attributes</tt>) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one.</p></div>
+</div>
+<h2 id="_credits">3. Credits</h2>
<div class="sectionbody">
</div>
-<h2 id="_changelog">3. Changelog</h2>
+<h2 id="_changelog">4. Changelog</h2>
<div class="sectionbody">
<div class="para"><p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks">http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks</a></p></div>
</div>
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 792c154f9e..b1fdfced05 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -22,6 +22,11 @@ There are several ways to validate the data that goes to the database, like usin * Implementing validations only at the client side can be problematic, specially with web-based applications. Usually this kind of validation is done using javascript, which may be turned off in the user's browser, leading to invalid data getting inside your database. However, if combined with server side validation, client side validation may be useful, since the user can have a faster feedback from the application when trying to save invalid data. * Using validation directly into your Active Record classes ensures that only valid data gets recorded, while still keeping the validation code in the right place, avoiding breaking the MVC pattern. Since the validation happens on the server side, the user cannot disable it, so it's also safer. It may be a hard and tedious work to implement some of the logic involved in your models' validations, but fear not: Active Record gives you the hability to easily create validations, using several built-in helpers while still allowing you to create your own validation methods. +== When does validation happens? + +There are two kinds of Active Record objects: those that correspond to a row inside your database and those who do not. When you create a fresh object, using the +new+ method, that object does not belong to the database yet. Once you call +save+ upon that object it'll be recorded to it's table. Active Record uses the +new_record?+ instance method to discover if an object is already in the database or not. Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either +save+, +update_attribute+ or +update_attributes+) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one. + + == Credits |