# Exclude a property on a model from save operations?

**URL:** <https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304>\
**Category:** Rails\
**Created:** [March 9, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304 "2007-03-09T15:39:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 9, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304/1 "2007-03-09T15:39:28Z")

</div>

Hey guys 🙂

I have some models that include computed fields, i.e. fields that  
aren’t data as such on a table, but are computed using other fields in  
the table, like author.printed\_name which is computed (on the sql  
server) by concatenating first names, last name, and name suffix.

If a try to save a model that has a property like this, the sql server  
throws an error that it can’t modify a computed column. Which is  
understandable 🙂

I just don’t know how to prevent that particular property/column from  
being saved when doing author.save().

Anyone?

Thanks,

Daniel 🙂

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 9, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304/2 "2007-03-09T16:29:39Z")

</div>

Hi Daniel,

Daniel Smedegaard B. wrote:

> I have some models that include computed fields, i.e. fields that  
> aren’t data as such on a table, but are computed using other fields in  
> the table, like author.printed\_name which is computed (on the sql  
> server) by concatenating first names, last name, and name suffix.

Without having any intention of getting into a philosophical debate re:  
‘best way’ …

In Rails, you do this sort of thing in the Model rather than in the  
database. My recommendation would be to turn the field in the database  
into  
a ‘normal’ string, move the computation into a method in the model, and  
use  
a before filter to invoke it.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 9, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304/3 "2007-03-09T17:40:04Z")

</div>

Daniel Smedegaard B. wrote:

> being saved when doing author.save().  
> Have a look at the attr\_readonly patch at  
> [http://dev.rubyonrails.org/ticket/6896](http://dev.rubyonrails.org/ticket/6896)

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 9, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304/4 "2007-03-09T17:38:01Z")

</div>

And, if possible, remove the field from the DB entirely, and just use  
Rails  
to simulate a field that doesn’t really exist… unless there’s a  
specific  
reason for having your ‘faux’ field in the DB as opposed to in the  
environment accessing the DB.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 12, 2007, 11:47am UTC](https://www.ruby-forum.com/t/exclude-a-property-on-a-model-from-save-operations/88304/5 "2007-03-12T11:47:11Z")

</div>

Hey guys!

I had a look at the diff before doing anything else, and I didn’t like  
that approach too much, really. So I asked around today if any other  
application was actually going to use this computed column, and it  
turned out that no, only the Rails app would be using it.

So, I chose to discard it, and implement the concatenation in Rails.

Thanks for everyone’s tips!

Daniel 🙂
