Here’s a query:
@projects = @user.projects.includes(:company => :workers)
In my view, I want to order a list of these projects by the tags that belong to the company.
So, projects belonging to the company’s urgent tag come first, then elevated, then all others.
I think one way to do this is to define @companies, then define:
@urgent = @companies.tagged_with('urgent')
@elevated = @companies.tagged_with('elevated')
@others = @companies.tagged_with('urgent', 'elevated', :exclude => true)
# view:
@urgent.each do |u| ... end
@elevated.each do |e| ... end
@others.each do |o| ... end
1. How do I get @companies in the first place?
How can you collect all the companies together when the first query is the one I showed at the top? @companies = @projects.collect{|p| p.company} produces a non-searchable array.
I dont think you can do this without using 2 queries.
As for rendering the tags, you could do: