Rails with database design without Rails

Complete the newbie by exploring Rails. Can Rails be used with a read-only schema that does not comply with the standard Rails naming and design conventions?

For example, my database schema has base tables that use row columns for unique primary keys. For example, a base table called Jobs may have a unique primary key defined as Jobs.Job, and the value may be "D01234". Now Jobs's child can be CostCodes, where the unique primary key is a combination of CostCodes.Job (FK link back to the Jobs table) and CostCodes.CostCode (local string column).

What it's worth ... is the Sage Timberline Office database.

Any pointers?

+3
source share
4 answers

Yes, it can be done.

Dave Thomas blog post describing a bit of what is needed: directives such as

set_table_name  "orders"
set_primary_key "o_id"

in ActiveRecord model definitions.

Some more links:

Googling for the "activeerecord legacy database" should pick up some more.

+5
source

You need to open the model for your specific table and set the following:

set_table_name 'user'
set_primary_key 'user_name'

And if you are managing relationships, you can explicitly specify a connection table:

has_and_belongs_to_many :page, :join_table => 'user_page'
+4
source

, ActiveRecord ( ORM) , , - . .

You can also replace ActiveRecord with another ORM, which is more flexible. DataMapper is a replacement that seems to have some traction.

+1
source

Other answers already address your question, but Apress is a great resource for all of these ActiveRecord questions. Apress is Pro ActiveRecord, that's really good, you should check it out.

0
source

Source: https://habr.com/ru/post/1704853/


All Articles