设计问题:位置模型的别名 (Rails)
这更多的是一个一般性的设计问题,但它将在 RoR 中实现,而我对 RoR 来说是个新手。另外,我认为这是我的第一个问题,所以请保持温和:)
场景是:
我有一个资产模型。每个资产都位于一个特定的房间中,因此我还希望与位置模型建立一对多的关系。够简单的。然而,一些房间(位置)也有一个别名(例如,123 又名图书馆)。当用户想要更新有关特定资产的信息时,我希望他们能够进行搜索,而不必担心他们是否知道确切的房间号,并显示该房间中的资产列表。
需要澄清的是,可能有多个别名。
所以问题是:
您会推荐一个位置具有一对多关系的 Alias 模型吗?或者,自我参照(某种层次结构)关联会更好吗?或者也许还有别的什么?根据我的设想,前者需要查询不同表上的列以获取相同类型的信息,而后者似乎不太正确(别名与位置不同)。
This is more of a general design question, but it will be implemented in RoR to which I am very much a newcomer. Also, I think this is my first question so please be gentle :)
The scenario is:
I have an Asset model. Each asset is located in a particular room, so I would also like a one-to-many relationship with a Location model. Simple enough. However, some rooms (Locations) also go by an alias (eg. 123 is aka Library). When a user wants to update information about a particular Asset, I would like them to be able to just search without worrying about whether they know the exact room number, and be shown a list of assets in that room.
To clarify, there could be more than one alias.
So the question is:
Would you recommend an Alias model for which a Location would have a one-to-many relationship? Or, would a self-referential (sort-of hierarchical) association be better? Or something else maybe? From what I can envisage, the former would require querying columns on different tables for the same sort of information, and the latter just doesn't seem right (an Alias is not the same as a Location).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是使用标记插件acts-as-taggable-on的好地方:
https: //github.com/mbleigh/acts-as-taggable-on
在您的模型中,您可以执行以下操作:
然后在您的控制器中执行以下操作:
This might be a good area for using the tagging plugin acts-as-taggable-on:
https://github.com/mbleigh/acts-as-taggable-on
In your model you can do:
Then in your controller do: