Column Names in Legecy Tables

Hi,

I’m using Rails with DB2 Database. The tables in the database are NOT
rails conventions, and there is no ‘id’ column too in the tables.

Hnece in the Model i’m setting the table name like this

ModelEmployee.set_table_name “employee”

Now if i try to print the colulmn names, it does not print anything, i
have tried to print the column name as below, but its not printing
anything.

ModelEmployee.set_table_name “employee”
puts ModelEmployee.column_names
puts ModelEmployee.content_columns

Hence if we are using Legecy Database, how should we access the column
names of the corresponding model?

Thanks.
Dinesh

maybe like this :

class Employee < ActiveRecord::Base
set_table_name “employee”

end

the in irb:

puts Employee.column_names

maybe show us the table structure, would be helpfull to see it,
concering primary key setup and the like …

Dinesh wrote:

I’m using Rails with DB2 Database. The tables in the database are NOT
rails conventions, and there is no ‘id’ column too in the tables.

Can you use the SQL VIEW statement to rename things to Rails’s liking?
VIEW is very powerful, and could fix the “problem” at its source.

In a multi-layered system like a website stack, I always seek to solve
the problem in the most convenient (and efficient) layer…


Phlip

Phlip wrote:

Dinesh wrote:

I’m using Rails with DB2 Database. The tables in the database are NOT
rails conventions, and there is no ‘id’ column too in the tables.

Can you use the SQL VIEW statement to rename things to Rails’s liking?
VIEW is very powerful, and could fix the “problem” at its source.

In a multi-layered system like a website stack, I always seek to solve
the problem in the most convenient (and efficient) layer…


Phlip

You could use the DrySQL Ruby plugin: http://drysql.rubyforge.org

It will automatically identify all your keys, and generate all the
associations and validations for your ActiveRecord data class, even if
you do not follow the ActiveRecord naming conventions.

All you need to do is name your table according to ActiveRecord naming
conventions OR call set_table_name in your class definition, and DrySQL
handles the rest.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs