Forum: Ruby on Rails ActiveRecord and database metadata. How much can I get?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-05-31 22:06
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
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-05-31 23:39
(Received via mailing list)
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.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-06-01 06:42
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
This topic is locked and can not be replied to.