Closed cat-in-136 closed 6 years ago
I assumed following code. But it does not work because of belongs_to :heartable, :polymorphic => true
.
Heart.where(:heartable => {:project => @project}).
group(:heartable_type, :heartable_id).
order(:created_at => :desc).
offset(@offset).
limit(@limit).
pluck(:heartable)
Or, it is better to add project_id
to the Heart
model? (but i don't know how to implement it.)
Thanks for your work. I like the "like" plugin. Can I see the "like" data in the issue list?
Candidate code to get "Like!" on the specific project @project
.
scope = [
Heart.where(:heartable => Board.where(:project_id => @project.id)),
Heart.where(:heartable => Issue.where(:project_id => @project.id)),
Heart.where(:heartable => Message.joins(:board).where(:boards => {:project_id => @project.id})),
Heart.where(:heartable => News.where(:project_id => @project.id)),
Heart.where(:heartable => Wiki.where(:project_id => @project.id)),
Heart.where(:heartable => WikiPage.joins(:wiki).where(:wikis => {:project_id => @project.id})),
Heart.where(:heartable => Journal.where(:journalized => Issue.where(:project_id => @project.id))),
].reduce { |scope1, scope2|
Heart.where(
Heart.arel_table.grouping(scope1.where_values.reduce(:and)).or(
Heart.arel_table.grouping(scope2.where_values.reduce(:and))
)
).tap { |scope| scope.bind_values = scope1.bind_values + scope2.bind_values }
}
hearts = scope.
group(:heartable_type, :heartable_id).
order(:created_at => :desc).
offset(@offset).
limit(@limit)
The development for this enhancement is on-going on the hearts-per-project branch.
It is useful to show all the "Like!" on a project.
But I could not write query...