# Where is save\_without\_validation?

**URL:** <https://www.ruby-forum.com/t/where-is-save-without-validation/108857>\
**Category:** Rails\
**Created:** [July 8, 2007, 7:31am UTC](https://www.ruby-forum.com/t/where-is-save-without-validation/108857 "2007-07-08T07:31:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 8, 2007, 7:31am UTC](https://www.ruby-forum.com/t/where-is-save-without-validation/108857/1 "2007-07-08T07:31:24Z")

</div>

Can someone tell me where this is at or how it gets created? There must  
be some magic to it.

Thank you,  
Perry

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 8, 2007, 10:45am UTC](https://www.ruby-forum.com/t/where-is-save-without-validation/108857/2 "2007-07-08T10:45:10Z")

</div>

> > a = Author.new(:name =\> “Test”)  
> > =\> #\<Author:0x34eaa54 @attributes={“name”=\>“Test”, “email”=\>nil,  
> > “created\_at”=\>nil}, @new\_record=true\>  
> > a.save  
> > =\> false  
> > a.errors  
> > =\> #\<ActiveRecord::Errors:0x34e92f8 @base=#\<Author:0x34eaa54  
> > @errors=#\<ActiveRecord::Errors:0x34e92f8 …\>, @attributes=  
> > {“name”=\>“Test”, “modified\_at”=\>nil, “url”=\>nil, “is\_active”=\>false,  
> > “hashed\_pass”=\>nil, “email”=\>nil, “created\_at”=\>nil},  
> > @new\_record=true\>, @errors={“email”=\>[“can’t be blank”]}\>  
> > a.save(false)  
> > =\> true

Zach I.  
â†’ Blog – [http://www.zachinglis.com](http://www.zachinglis.com)  
â†’ Company – [http://www.lt3media.com](http://www.lt3media.com)  
â†’ Portfolio – [http://portfolio.zachinglis.com](http://portfolio.zachinglis.com)  
â†’ Web Designer â†’ Print Designer â†’ Identity Desginer â†’ Ruby on  
Rails developer â†’ et plus.  
â†’ AIM: zachinglis â†’ MSN: removed\_email\_address@domain.invalid â†’ Others  
available on request

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 8, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/where-is-save-without-validation/108857/3 "2007-07-08T14:47:47Z")

</div>

Perry S. wrote:

> Can someone tell me where this is at or how it gets created? There must  
> be some magic to it.

In active\_support/core\_ext/module/aliasing.rb, there is a instance  
method added to module called alias\_method\_chain. It is used in a lot  
of places, like validations.rb around line 221. You see:

```
    alias_method_chain :save, :validation
    alias_method_chain :save!, :validation
    alias_method_chain :update_attribute, :validation_skipping

```

This creates two aliases as described by the comments:

# alias\_method\_chain :foo?, :feature

# 

# is equivalent to

# 

# alias\_method :foo\_without\_feature?, :foo?

# alias\_method :foo?, :foo\_with\_feature?

So, in this case save\_without\_validation points to what save use to  
point to and now save points to save\_with\_validation. So, in the code,  
you will see a call to save and in the stack trace. But the line  
numbers will be inside save\_with\_validation. (or foo\_with\_feature in  
the general case). foo\_with\_feature will then usually call  
foo\_without\_feature to call the original foo routine.

Pretty nifty trick.

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 8, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/where-is-save-without-validation/108857/4 "2007-07-08T16:28:41Z")

</div>

Zach I. // LT3media wrote:

> > > a.save(false)  
> > > =\> true

A\> What’s wrong with calling save\_without\_validation? Is that  
/de-facto/ private?

B\> validations involving unique table keys require lots of  
database hits, so saving without validation is faster,  
right?

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
