rails计数双项 [英] rails count double entries

查看:94
本文介绍了rails计数双项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接表:

<% @users.each do |user| %>
<li><%= user.user_id %><%= user.user.name %></li>

给我


  • 1 fred

  • 1 fred

  • 9 charlie

好..感谢到目前为止的答案。我可以看到,我不够精确到足以解释我需要什么。

Well.. thanks so far for the answers. I can see that I was not precise enough to explain what I need.

<% @users.each do |user| %>
<li><%= user.user_id %><%= user.user.name %></li>

是查询的结果。所以结果可以是10个不同的用户,或者一些可以是双倍或三倍。我想要标记他们当他们出现multipe。我不想在我的数据库中找到双重条目.....

is the result on an query. So the result could be 10 different user or some could be double or triple. I want to mark them when they appear multipe. I dont want to find out double entries in my database.....

所以我必须找出天气| user |是多个val与相同user_id..to得到一个真/假
希望这使它更清楚。
现在我没有clou如何archieve这。

So I have to find out weather in |user| are mutiple val with the same user_id..to get a true/false Hope this makes it more clear. Right now I dont have clou how to archieve this.

推荐答案

如果用户表引用本身, user.users.count 应该返回引用此文件的其他用户的数量。

If the user table references itself, then something like user.users.count should return the amount of other users referencing this one.

这篇关于rails计数双项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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