Rails与非Rails数据库设计 [英] Rails with Non-Rails Database Design

查看:88
本文介绍了Rails与非Rails数据库设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成新手研究Rails。 Can Rails可以使用不符合Rails默认命名和设计约定的只读模式吗?



例如,我的数据库模式具有使用字符串列作为唯一主键的基表。例如,名为Jobs的基表可能具有定义为Jobs.Job的唯一主键,该值可能为D01234。现在,Jobs的子实体可能是CostCodes,其中唯一主键是CostCodes.Job(返回Jobs表的FK引用)和CostCodes.CostCode(本地字符串列)的聚合。



这是值得的...这是股票Sage Timberline Office数据库。



任何指针? / p>

解决方案

是的,可以。



Dave Thomas < a href =http://pragdave.pragprog.com/pragdave/2006/01/sharing_externa.html =nofollow noreferrer>一篇博客文章,描述了一些必要的指令:

  set_table_nameorders
set_primary_keyo_id


更多参考资料:





Google搜索activerecord legacy database应该可以更多了。


Complete newbie researching Rails. Can Rails be used with a read-only schema that doesn't conform to the Rails' default naming and design conventions?

For example, my database's schema has base tables that use string columns for unique primary keys. For example, a base table called Jobs, might have a unique primary key defined as Jobs.Job and the value might be 'D01234'. Now, a child entity of Jobs might be CostCodes where the unique primary key is the aggregate of CostCodes.Job (an FK reference back tothe Jobs table) and CostCodes.CostCode (a local string column).

For what it's worth... this is the stock Sage Timberline Office database.

Any pointers?

解决方案

Yes, it can be done.

Dave Thomas has a blog post describing a little of what's necessary: directives such as

set_table_name  "orders"
set_primary_key "o_id"

in your ActiveRecord model definitions.

Some more references:

Googling for "activerecord legacy database" ought to pick up some more.

这篇关于Rails与非Rails数据库设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆