# Save ActiveRecord attribute without type checking

**URL:** <https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873>\
**Category:** Rails\
**Created:** [August 12, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873 "2007-08-12T21:02:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumboboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jumboboy](https://www.ruby-forum.com/u/jumboboy)\
**Post date:** [August 12, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873/1 "2007-08-12T21:02:23Z")

</div>

I want to do a “raw” update an attribute on a ActiveRecord model  
without Rails doing type checks on the underlying column in my db.

In other words - I want the create/update equivalent of  
“attributes\_before\_type\_cast” which I can use when i read the column.

In my particular example I would like to set a DATE column in Mysql to  
“1970-00-00” for example. Mysql lets me set this value in a DATE  
column. When I try to set this value in Rails, the column gets nulled  
out.

Appreciate any help on this  
–Mats

---

<div class="post-metadata">

**Author:** ![jumboboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jumboboy](https://www.ruby-forum.com/u/jumboboy)\
**Post date:** [August 12, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873/2 "2007-08-12T23:53:38Z")

</div>

Use SQL, inside your model.

sql = ActiveRecord::Base.connection()  
sql.execute(“sql statement for whatever you want to do;”)

You can wrap this around a particular private function that you write.

Vish

---

<div class="post-metadata">

**Author:** ![jumboboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jumboboy](https://www.ruby-forum.com/u/jumboboy)\
**Post date:** [August 13, 2007, 3:48am UTC](https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873/3 "2007-08-13T03:48:56Z")

</div>

Hi Mats,

Not sure I understand your request, but you might be looking for  
save.with\_validations(false)

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![jumboboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jumboboy](https://www.ruby-forum.com/u/jumboboy)\
**Post date:** [August 14, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/save-activerecord-attribute-without-type-checking/111873/4 "2007-08-14T19:08:41Z")

</div>

Vish - that worked fine!

Thanks a lot!  
–Mats
