Forum: Ruby on Rails conditional join selection with active record

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
inriz (Guest)
on 2008-10-15 13:42
(Received via mailing list)
hello list,

i'm searching for an implementation of the following sql statement:

SELECT inserent.* FROM inserent
join
(select objpriv.maknr from objpriv
where objpriv.bankkto like '593%' and objpriv.zahlart = 'B'
group by objpriv.maknr) o on o.maknr = inserent.insnr

ORDER BY
 inserent.AENDDATUM desc

evidently, i solved my problem with

@advertisers = Advertiser.paginate(  :select => "inserent.*", :order =>
"inserent.AENDDATUM desc", :from => "inserent join (select
objpriv.maknr from objpriv where objpriv.bankkto like '#{query}' and
objpriv.zahlart = 'B' group by objpriv.maknr) o on o.maknr =
inserent.insnr")

but, the pagination is broken.
i know i'm abusing the from parameter for my needs

what's the way to implement it?

thanks for all your help

best regards
Frederick C. (Guest)
on 2008-10-15 14:38
(Received via mailing list)
On 15 Oct 2008, at 10:41, inriz wrote:

>
>
> but, the pagination is broken.
> i know i'm abusing the from parameter for my needs

Use the :joins parameter ?

Fred
This topic is locked and can not be replied to.