在Ruby on Rails中在运行时构建表 [英] Build a table at runtime in Ruby on Rails

查看:116
本文介绍了在Ruby on Rails中在运行时构建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时创建多个数据库表使用相同的模型,如果rails想从模型名称推断表名称?我想要能够基于模型创建一个新对象,然后创建一个具有该对象将引用的唯一名称的新表。

How would I go about creating multiple database tables at runtime that utilize the same model given that rails wants to infer the table name from the model name? I want to be able to create a new object based on a model, then create a new table with a unique name that the object will reference. Does anyone have any examples or advice they can share to help me find a solution?

推荐答案

这听起来像是一个架构问题 - 为什么您将拥有相同模型的克隆,而不是将它们全部存储在同一个表中?

This sounds like an architectural problem - why would you have clones of the same model instead of storing them all in the same table?

在关系数据库模型中,关系定义了一个行或元组,它是关于密钥的属性集。任何其他类似的属性集属于同一关系(表)。

In the relational database model, a relation is what defines a row or tuple, meaning it is the set of attributes about the key. Any other similar sets of attributes belong in the same relation (table).

这篇关于在Ruby on Rails中在运行时构建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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