Answer the question
In order to leave comments, you need to log in
[Ruby,Sinatra,Datamapper] How to select elements by association order by father ID?
Hello!
I have a Mainstack model that has belongs_to :song and a Song model that has n, :mainstacks
I need to select Mainstack.all.songs but sort it by parent Mainstack ID
Mainstack.all(:order => [id] ).songs doesn't work, still sorted by songs.id
Answer the question
In order to leave comments, you need to log in
Since you write in ruby, then write correctly
Well, sorting can be done like this
@songs = Song.all(:order => [Song.mainstacks.id.desc])
@Mainstacks = Mainstack.all( :order => [:id.desc])
@songs = []
@Mainstacks.each do |mainstack|
@songs << mainstack.song
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question