Hey, Jeremy.

Thank you very much, I was able to successfully complete the query:

query = DB[:users]
    .join(:snippets, user_id: :id)
    .join(:snippets_tags, snippet_id: :id)
    .join(:tags, id: :tag_id)
    .where {
        Sequel.&(
          {:user_id=>user.id},
          {Sequel[:tags][:description]=>'language'}
        )
    }
    .group_and_count(Sequel[:tags][:id]) # Now, need order by this count desc
    .select_append(Sequel[:tags][:name])
    .limit(6)
    .all



Now I am trying to order the records in descending order using counted tags 
using group_and_count() 
But I suppose I need to create an alias for this value and call it in the   
.order(Sequel.desc(:tags_counted))

Tried: 

query = DB[:users]
    .join(:snippets, user_id: :id)
    .join(:snippets_tags, snippet_id: :id)
    .join(:tags, id: :tag_id)
    .where {
        Sequel.&(
          {:user_id=>user.id},
          {Sequel[:tags][:description]=>'language'}
        )
    }
    .group_and_count(Sequel[:tags][:id].as(:tags_counted)) # alias
    .select_append(Sequel[:tags][:name])
    .order(Sequel.desc(:tags_counted)) # Try order by tags count alias
    .limit(6)
    .all






But the result is that the id of each record is now called tags_counted and 
is being sorted in descending order. 

I understand that it happened, but I do not see how to create an alias for 
the values of

group_and_count(Sequel[:tags][:id])


ps: *Any Suggestions? With this the query will be ready *

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to