当前位置:网站首页>Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
2022-07-02 22:49:00 【Technology feast】
problem :
I have a model named Song . I have a name called Song Model of .I also have a model named Listen . I have another one called Listen Model of .A Listenbelongs_to :song , and a song :has_many listens (can be listen to many times).A Listenbelongs_to :song And songs :has_many listens ( You can listen to it many times ).
In my model I want to define a method self.top which should return the top 5 songs listened to the most. In my model , I want to define a method self.top , It should return to the top of the list 5 A song .How can I achieve that using the has_many relation? How to use has_many Relationships achieve this ?
I'm using Rails 3.1. I am using Rails 3.1.
Thanks! thank you !
Solution :
Reference resources : https://stackoom.com/en/question/aUE9边栏推荐
- PMP项目整合管理
- Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
- Simpleitk use - 4 Strange question
- 傑理之修改不需要長按開機功能【篇】
- LxC terminal login method
- [foreign journal] sleep and weight loss
- Golang面试整理 三 简历如何书写
- Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
- [shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
- 杰理之如何测试按键的误触率【篇】
猜你喜欢
![[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)](/img/2b/f31b81cedf37ca187bcaa20dfe0b83.png)
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed

对象与对象变量

Wait to solve the zombie process

UE4 game architecture learning notes

【外刊】睡眠与减肥

Mathematical modeling -- graph and network models and methods (I)

Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning

Source code analysis - lightweight asynchronous crawler framework Ruia
![[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)](/img/f7/cb41d159e5c5ef3f4f1b9468d52ccc.jpg)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
随机推荐
杰理之修改不需要长按开机功能【篇】
Market Research - current market situation and future development trend of handheld wound imaging equipment
Objects and object variables
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
送给即将工作的自己
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
[LeetCode] 反转字符串【344】
[LeetCode] 存在重复元素【217】
Phpcms realizes the direct Alipay payment function of orders
Market Research - current market situation and future development trend of total nutrition products
LxC terminal login method
Graphic view frame
`${}`的用法
数据库系统概论第一章简答题-期末考得怎么样?
Mathematical modeling -- graph and network models and methods (I)
傑理之修改不需要長按開機功能【篇】
Oracle-游标
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...