ruby-on-rails - 计算 Rails 中不同的属性对
问题描述
我有一堂课Restaurant
:
Restaurant(id: integer, name: string, url: string, address: string
我想得到和计算它们的所有不同url
组合name
。我怎样才能做到这一点?
我试过了
Restaurant.select(:url, :name).distinct.count
但我得到:
No function matches the given name and argument types. You might need to add explicit type casts.
解决方案
你试过了吗?
Restaurant.pluck(:url, :name).uniq.count
更多在这里http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-pluck
推荐阅读
- javascript - NodeJS map() 函数通过执行一些 DB 操作返回新对象并返回操作结果
- python - Matplotlib中相同轴的不同间距
- javascript - 在 p5.js 中显示地图的问题
- angular - 无法将数据从服务传递到 Angular 中的组件
- mysql - SQL好友列表查询
- asp.net - ListView 中的 ASP.NET DropdownList
- javascript - 在第一个动画 css 的位置开始第二个动画 css
- neural-network - caffe:带有单个过滤器的卷积层的总和
- windows - AWS 命令行界面在通过 MSI 安装后失败
- javascript - MYSQL - 检查 var 是否存在,如果存在则更新