ActiveRecord and database metadata. How much can I get?


#1

All,

I have need of getting at some underlying database metadata for
ActiveRecord descendants.

Does anyone know if I can get access to the following attributes of the
underlying column for a given ActiveRecord object:

Is it a currency object?
Is it nullable?
Is it a signed int?
Is it searchable?
Column length
Column name
Column precision
Column scale
Column data type - how specific can I get here?

I’m ok with digging into the ActiveRecord::Base object if I have to and
mucking around with it.

I figure this metadata must be lingering somewhere in order for the
database operations to work.

Thanks,
Wes


#2

Hello Wes,

Column length
Column name
Column precision
Column scale
Column data type - how specific can I get here?

I’m ok with digging into the ActiveRecord::Base object if I have to and
mucking around with it.

See AR::Base#columns and AR::Base#columns_hash
You can also look at the scaffold generated code to understand how
it can be used.

I figure this metadata must be lingering somewhere in order for the
database operations to work.

Regards,

-- Jean-François.

#3

Jean-François wrote:

Hello Wes,

Column length
Column name
Column precision
Column scale
Column data type - how specific can I get here?

I’m ok with digging into the ActiveRecord::Base object if I have to and
mucking around with it.

See AR::Base#columns and AR::Base#columns_hash
You can also look at the scaffold generated code to understand how
it can be used.

I figure this metadata must be lingering somewhere in order for the
database operations to work.

Regards,

-- Jean-François.

Jean-Francois,

Thanks for the help. Looking at the sqlserver driver for active record
was quite helpful and gave me what I needed.

Wes