当前位置:网站首页>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 Listen
belongs_to :song
, and a song :has_many listens
(can be listen to many times).A Listen
belongs_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边栏推荐
- [LeetCode] 多数元素【169】
- Jerry's modification does not require long press the boot function [chapter]
- Methods of adding styles to native JS
- Market Research - current situation and future development trend of preclinical medical device testing service market
- 'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
- Graphic view frame
- 《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
- How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
- [foreign journal] sleep and weight loss
- UE4 UI自适应屏幕
猜你喜欢
Oracle-游标
New feature of go1.18: introduce new netip Network Library
电商系统微服务架构
Dynamic memory allocation (malloc calloc realloc free)
【外刊】睡眠与减肥
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
NC24325 [USACO 2012 Mar S]Flowerpot
世界环境日 | 周大福用心服务推动减碳环保
Baidu AI Cloud - create a face recognition application
杰理之、产线装配环节【篇】
随机推荐
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
Regular expression (2)
UE4 UI自适应屏幕
服务器响应状态码
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
[LeetCode] 数组中的第K个最大元素【215】
Oracle cursor
Market Research - current situation and future development trend of preclinical medical device testing service market
Market Research - current situation and future development trend of cell-based seafood market
UE4 游戏架构 学习笔记
Market Research - current market situation and future development trend of third-party data platform
【洛谷P1541】乌龟棋【DP】
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
杰理之快速触摸不响应问题【篇】
《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】
U++ learning notes - relaxation
Pointer array parameter passing, pointer parameter passing
Oracle-PL/SQL编程
世界环境日 | 周大福用心服务推动减碳环保
Market Research - current situation and future development trend of sickle cell therapy Market