Activerecord's virtual attribute in find's array

hi guys

i have a product model with many columns like
cat1,cat2,cat3,name,desc,price,qty etc.

along with that i have a virtual attribute call full_name in model

attr_accessor :full_name

def full_name
cat1+cat2+cat3+name #something like this
end

when i do Product.find(:all)
in the product array the product’s hash object does not have a attrubute
with the name full_name.

although i know if i write prod.full_name it will work
i want that attribute to be in the hash as a key-value pair
as i want to convert the whole array to json.

what is the simplest way of doing this.

i had tried this but did not work

def after_find
full_name
end

thanks
jags

On 23 May 2008, at 13:59, Jags R. wrote:

although i know if i write prod.full_name it will work
i want that attribute to be in the hash as a key-value pair
as i want to convert the whole array to json.

to_json takes a :methods parameter where you can list methods to call
whose result should be in the json eg

products.to_json :methods => :[full_name]

Fred