# Active record logical cols

**URL:** <https://www.ruby-forum.com/t/active-record-logical-cols/163190>\
**Category:** Rails\
**Created:** [March 18, 2009, 5:56am UTC](https://www.ruby-forum.com/t/active-record-logical-cols/163190 "2009-03-18T05:56:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 18, 2009, 5:56am UTC](https://www.ruby-forum.com/t/active-record-logical-cols/163190/1 "2009-03-18T05:56:50Z")

</div>

HI,

I am new to Rails started project couple of weeks back. Here is my  
requirement please let me know the solution.

```
When I do find on my active record class it returns all the

```

columns in my database table. I want to add one or two more cols to  
the return record.

Like Student.find returns dob and name I want to add age to it some  
thing like that. Columns that are not exist in the database table but  
I want to add to the return record. How can I do this??

Please reply asap I am totally struck on this.

Thanks,  
Ramu.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 18, 2009, 7:07am UTC](https://www.ruby-forum.com/t/active-record-logical-cols/163190/2 "2009-03-18T07:07:42Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Like Student.find returns dob and name I want to add age to it some  
> thing like that. Columns that are not exist in the database table but  
> I want to add to the return record. How can I do this??

Age would just be a method on the Student model calculated from DOB:

class Student \< ActiveRecord::Base

def age  
age = x # I’ll assume you can figure out how to calculate age from DOB  
end

Getting access to the existing attributes like date\_of\_birth is a simple  
as:

self.date\_of\_birth # self in this case means the current instances of  
the Student class since this is an instance method.

Remember that Ruby will return the value of the last line of the method  
automatically so you don’t have to include the return.
