Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to map non-standard table with ActiveRecord or should I use other ORM?

I'm using a tool(UltraSms) that required three tables named (smsin, smsout & smsparts)

I need these tables to be used in the same Rails application that has other tables. With ActiveRecrod I know that table names has to be plural of the Active record class name by convention. Is there a way to map those to an ActiveRecrod class easily or should I find manual way to do ORM for it?

Thanks,

Tam

like image 934
Tam Avatar asked Jun 02 '09 08:06

Tam


People also ask

Is ActiveRecord an ORM?

ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code.

What does ActiveRecord base do?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending. Edit: as Mike points out, in this case ActiveRecord is a module...

What is Rails ActiveRecord?

Rails Active Records provide an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records. Ruby method names are automatically generated from the field names of database tables.


2 Answers

Seems that in Rails3.1 , the method name changed to table_name=, e.g.

class Mouse < ActiveRecord::Base
  self.table_name = "mice"
end
like image 133
Siwei Avatar answered Nov 01 '22 13:11

Siwei


You can do this:

class MyClass < ActiveRecord::Base
  set_table_name "smsin"
end
like image 44
A.Ali Avatar answered Nov 01 '22 12:11

A.Ali