Put alias in Model.find query

Hi to all,

I want to be able to put alias to my Song.find query.
the artist field belongs to song model so that i could code efficiently
in sorting columns. I want to put an (s) alias to my Song model.

In the code below :select => “artist, g.genre_name AS name_genre”
should be
:select => “s.artist, g.genre_name AS name_genre”

In my controller:

@q = Song.find(:all, :select => “artist, g.genre_name AS name_genre”,
:joins => “LEFT OUTER JOIN genres AS g on songs.genre_id = g.id”, :order
=> params[:sort])

In my view:

<%= link_to "Artist", :sort => "artist"%> <%= link_to "Genre", :sort => "genre_name"%>

Anyone has an idea how to do this?

Uhm…I figured out how to do it…

Song.find(:all, :select => “AS s artist, g.genre_name AS name_genre”,
:joins => “LEFT OUTER JOIN genres AS g on songs.genre_id = g.id”, :order
=> params[:sort])

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs