带有Mongoid和Rails的字段别名 [英] Field aliases with Mongoid and Rails

查看:82
本文介绍了带有Mongoid和Rails的字段别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MongoDB中,通常的做法是使用短键名来节省空间.例如,可能要使用"fn"而不是"first_name"

It's common practice in MongoDB to use short key names to save space. For example, one might want to use "fn" instead of "first_name"

但是,在您的应用程序中,如果到处都使用"fn",则会很麻烦.太丑了特别是对于Rails,在Mongoid中声明字段时,是否有一种简单的方法来指定别名?

However in your app, you're screwed if you use "fn" all over the place. It's too ugly. For Rails specifically, is there an easy way to specify an alias when declaring a field in Mongoid?

还有,有人知道使用Mongoid的任何开源示例项目吗?

Also, does anyone know of any open source sample projects that use Mongoid?

谢谢!

推荐答案

您应该考虑使用

 field :fn, :as => :firstname

如此处概述: http://groups.google.com/group/mongoid/browse_thread/thread/ce3298d6a167bd70

这是一个非常好的做法,在mongoid中得到了完全支持.

this is a very good practice which is fully supported in mongoid.

这篇关于带有Mongoid和Rails的字段别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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