0
加入嵌套协会,团体和秩序我有嵌套的模型结构:通过计数
class Forum < ActiveRecord::Base
has_many :topics
class Topic < ActiveRecord::Base
has_many :posts
belongs_to :forum
class Post < ActiveRecord::Base
belongs_to :topic
has_many :post_links
has_many :links, ->{ uniq }, through: :post_links, dependent: :destroy
class PostLink < ActiveRecord::Base
belongs_to :post
belongs_to :link
class Link < ActiveRecord::Base
has_many :post_links
has_many :posts, ->{ uniq }, through: :post_links, dependent: :destroy
所以我想这是帖子说是主题,在论坛,ID = 1
所有链接按照论坛中出现的次数降序排列。
所以,如果我有一些职位youtube.com
5次论坛,ID = 1,和10时google.com
话,我想有这样的:
id,name,mentions_count
1,google.com,10
2,youtube.com,5
计数什么? – emrahbasman
在这个论坛的所有帖子链接提及次数。 –
在论坛1中订购帖子的链接数量? – emrahbasman