On 24 December 2011 18:50, Fresh Mix <li...@ruby-forum.com> wrote:
> Brynjolfur Thorvardsson wrote in post #1037995:
>
>> @var1 = @friends.where(<select 1>)
>> @var2 = @friends.where(<select 2>)
>>
>> @friendsfound = @var1 + @var2
>
>
> tmp1 = Friendships.includes(:users).select("uid1 as user_id",
> status).where("uid2 = (?)", @user.id)
> tmp2 = Friendships.includes(:users).select("uid2 as user_id",
> status).where("uid1 = (?)", @user.id)
> @friends = tmp1 + tmp2
>
> Tested, it works, but the only problem is ordering.
>
> How to order:
>
> .order("FIELD( friendships.status, 'lover', 'best friend', 'partner',
> 'enemy' ), users.name")

Because you are adding the two collections together you will have to
sort it afterwards.  Have a look at Array#sort and sort_by.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to