的Ruby / Rails的 - 进入A"查找"表而不造型呢? [英] Ruby/Rails - Access a "lookup" table without modeling it?

查看:144
本文介绍了的Ruby / Rails的 - 进入A"查找"表而不造型呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个Ruby on Rails的3.0.x的项目。

This is for a Ruby on Rails 3.0.x project.

我有一个查找表中的数据从一个供应商。

I have a "lookup" table with data from a vendor.

当我从另一个源导入数据,我想查这个表(合并在一个SKU),额外的数据。

When I import data from another source, I want to check this table (join on a SKU) for extra data.

它似乎没有权利我在我的应用程序创建一个模型,这个表。数据永不通过我的应用程序而改变,并且它不需要具有超出我刚提到的数据查找任何模型关联。它只是偶尔访问,以检查一些信息。

It doesn't seem right to me to create a model for this table in my app. The data will never be changed by my app, and it doesn't need to have any model associations beyond the data lookup I just mentioned. It's just occasionally accessed to check for some info.

什么是访问该表中的最佳实践?

What is the best practice to access this table?

感谢。

推荐答案

有在创造它周围的模型没有坏处,但如果你想避免它,你将不得不派出原始的SQL查询到数据库来获得回数据作为替代。

There's no harm in creating a model around it, but if you'd like to avoid it, you will have to send raw SQL queries to the DB to get data back as an alternative.

生疑问:<一href="http://www.rabbitcreative.com/2007/06/08/executing-raw-sql-in-rails/">http://www.rabbitcreative.com/2007/06/08/executing-raw-sql-in-rails/

在另一方面,我认为动机环绕它周围的模型超越了你是否要修改它。我绝对有大约有表,永远不会改变(应用程序特定的术语,即一个列表,城市/州的列表,而导入一次,从来没有改变过其他静态数据)模型的应用程序。 ActiveRecord的也将换列到交通方便的方法,让您可以轻松读取这些数据,更何况身边排序,查找,等一切方便的方法。

On the other hand, I think the motivation for wrapping a model around it goes beyond whether or not you want to modify it. I definitely have apps that have models around tables that never change (i.e. a list of app-specific terminology, a list of cities/states, and other static data that is imported once and never changed). ActiveRecord will also wrap the columns into easily accessible methods, so you can read that data easily, not to mention all the convenience methods around sorting, finding, etc.

这篇关于的Ruby / Rails的 - 进入A&QUOT;查找&QUOT;表而不造型呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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