how can i know type of attribute with active record

Hello,

In my database, I have a table "products" with attributes :
- id
- title ->string
- desc -> text

I use active record, but I don't know why recover the type of this
attribute with active record?

I try attributes_before_type_cast but I don't see the type

Can you help me?

Excuse for my english (I'am a young student french)

Richard Vincent wrote:

Hello,

In my database, I have a table "products" with attributes :
- id
- title ->string
- desc -> text

I use active record, but I don't know why recover the type of this
attribute with active record?

I try attributes_before_type_cast but I don't see the type

Can you help me?

Excuse for my english (I'am a young student french)
  

Either of these should get you what you want.

MyClass.columns_hash['column_name'].type

@instance_of_my_class.column_for_attribute(:column_name).type

Although, I should mention that in nearly two years of developing in Rails professionally, I don't think I've ever needed to retrieve this information in any of my apps. Are you sure that what you really want isn't the ruby class of the value (eg. @instance.column_name.class ), or something else?

Ok thanks for your example, it's goog for my app

Other question :
In my database, I have a table "line_items" with attributes :
- id -> integer
- product_id -> integer
and I have a foreign key (product-id references table product)

It is possible to recover the class of attribute product_id?
In my app I list object in my database (like phpMyAdmin) and if a
foreign key I want to link to the object reference by this foreign key.

For example, in "line_items", list object of this table and I want a
link in "product_id" to this product

I don't know if it's possible???

Jon Garvin wrote: