Forum: Ruby on Rails singular table names testing

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.
Zac E. (Guest)
on 2006-04-03 23:03
I've demoed my rails app and now have to move it to a MSSQL DB.  the big
problem I'm running into is the table name conventions I have to use.

I have to use names like tbl_Transfer & tbl_User.   In my tests on the
console, I am trying

myvar = tbl_Transfer.find_by_sql("select top 1 * from tbl_Transfer")

NameError: undefined local variable or method `tbl_Transfer' for
#<Object:0xb7fec970>
        from (irb):1

what should go into the myvar= section?  the TableName correct?

thanks

-zaq
Jakob S. (Guest)
on 2006-04-04 09:35
(Received via mailing list)
On Apr 3, 2006, at 21:03, zac elston wrote:
> I have to use names like tbl_Transfer & tbl_User.   In my tests on the
> console, I am trying
>
> myvar = tbl_Transfer.find_by_sql("select top 1 * from tbl_Transfer")
>
> NameError: undefined local variable or method `tbl_Transfer' for
> #<Object:0xb7fec970>
>         from (irb):1
>
> what should go into the myvar= section?  the TableName correct?

In the above case, my guess is you need a model like:

class Transfer < ActiveRecord::Base
   set_table_name 'tbl_Transfer'
end

Then you'd be able to do

all_my_transfers = Transfer.find(:all)

Tablenames are generally abstracted away from your Rails application.
It just happens to be that models are usually named after your
tables. Your variables you can name anything.

--
Jakob S. - http://mentalized.net
This topic is locked and can not be replied to.